Skip to content

Instantly share code, notes, and snippets.

View suhanlee's full-sized avatar
:octocat:
Focusing

kyle suhanlee

:octocat:
Focusing
View GitHub Profile
@suhanlee
suhanlee / supervisor.ex
Created March 24, 2018 18:17
supervisor
defmodule Todo.SuperVisor do
use Supervisor
def init(_) do
processes = [worker(Todo.Cache, [])]
supervise(processes, strategy: :one_for_one)
end
end
@suhanlee
suhanlee / Keyvaluestore.ex
Last active March 24, 2018 16:18
genserver behaviour
defmodule KeyValueStore do
use GenServer
def init(_) do
{:ok, HashDict.new}
end
def handle_cast({:put, key, value}, state) do
{:noreply, HashDict.put(state, key, value)}
end
@suhanlee
suhanlee / keyvaluestore.ex
Last active March 24, 2018 14:20
generic server
defmodule KeyValueStore do
def start do
ServerProcess.start(KeyValueStore)
end
def put(pid, key, value) do
ServerProcess.call(pid, {:put, key, value})
end
@suhanlee
suhanlee / client.ex
Last active March 24, 2018 13:37
process_bottleneck.ex
server = Server.start
Enum.each(1..5, fn(i) ->
spawn(fn ->
IO.puts "Sending msg ##{i}"
response = Server.send_msg(server, i)
IO.puts "Response: #{response}"
end)
end)
@suhanlee
suhanlee / register.ex
Last active March 24, 2018 13:19
TodoServer
Process.register(self, :some_name)
send(:some_name, :msg)
receive do
msg -> IO.puts "received #{msg}"
end
@suhanlee
suhanlee / package.json
Last active March 15, 2018 18:30
react webpack configuration
{
"name": "react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.1.1"
},
"scripts": {
@suhanlee
suhanlee / index.js
Created February 25, 2018 16:30
code-push
import App from './app/index';
import CodePush from 'react-native-code-push';
const app = CodePush({
installMode: CodePush.InstallMode.IMMEDIATE,
updateDialog: true
})(App);
watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache
public class AppConfig extends WebMvcConfigurerAdapter{
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource bean = new ReloadableResourceBundleMessageSource();
bean.setBasename("classpath:messages");
bean.setDefaultEncoding("UTF-8");
return bean;
}
@Bean
@suhanlee
suhanlee / matplot1.py
Last active November 12, 2017 18:12
matplot
from matplotlib import pyplot as plt
years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3]
plt.plot(years, gdp, color='green', marker='o', linestyle='solid')
plt.title("Nominal GDP")
plt.ylabel("Billions of $")