Category Archives: StackOverFlow

Stack Overflow is a question and answer site for professional and enthusiast programmers.

How to get local data source in server side applications?

I am using blazor server side application. In that I need to refer local dataSource.

I have used the Http as like default client side sample.


    ChartData[] dataSource;
    protected override async Task OnInitAsync()
        dataSource = await Http.GetJsonAsync<ChartData[]>("scripts/aapl.json");

But I have been facing the issue like below,
enter image description here

Can anyone guide me to fix this?

How to get local data source in server side applications?

Lookup a dictionary of dictionaries in Python

I am trying to lookup a dictionary of dictionaries and facing difficulty to do so.

The dictionary looks like this:

CME {u'JPY': 0.525, u'USD': 3.305, u'CNH': 4.805}
EUREX   {u'USD': 3.305, u'GBP': 1.545, u'EUR': 0.375}
GOODM   {u'KRW': 0.0}
HKEX    {u'USD': 3.395, u'HKD': 3.565, u'CNH': 4.895}
KIS {u'KRW': 0.0}
NLFX    {u'USD': 3.305}
OSE {u'JPY': 0.615}
SGX {u'JPY': 0.725, u'USD': 2.605, u'SGD': 2.575, u'CNH': 5.005, u'CNY': 0.0}
TOCN    {u'JPY': 0.525}

When i do this: data['GOODM']['KRW'], i get 0. However, when i do this: data[margins['opp_pty_cd']][margins['cur']], i get this:

read more

How to wrap monadic action in IO

I am trying to treat a ReaderT X IO Monad as IO to achieve the following:

-- this is the monad I defined:
type Game = ReaderT State IO                                                                                                            

runGame :: State -> Game a -> IO a                                                                                                      
runGame state a = runReaderT a state                                                                                                    

readState :: Game State                                                                                                                 
readState = ask                                                                                                                         

-- some IO action, i.e. scheduling, looping, etc.                                                                                                                    
ioAction :: IO a -> IO ()
ioAction = undefined

-- this works as expected, but is rather ugly                                                                                                                                       
doStuffInGameMonad :: Game a -> Game ()                                                                                                 
doStuffInGameMonad gameAction = do                                                                                                      
  state <- readState                                                                                                               
  liftIO $ ioAction $ runGame state gameAction

read more