Skip to content

Instantly share code, notes, and snippets.

Toran Billups toranb

Block or report user

Report or block toranb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@toranb
toranb / gist:2372372
Created Apr 13, 2012
Auto workon virtualenv bash script based on current directory name
View gist:2372372
workon_virtualenv() {
if [ -e .git ]; then
current_dir="${PWD##*/}"
if [ -e ~/virtualenvs/$current_dir ]; then
deactivate >/dev/null 2>&1
source ~/virtualenvs/$current_dir/bin/activate
fi
fi
}
View actions.todos.js
import * as types from '../actions/types';
export const addTodo = text => dispatch => dispatch({type: types.ADD_TODO, text});
export const deleteTodo = id => dispatch => dispatch({type: types.DELETE_TODO, id});
export const editTodo = (id, text) => dispatch => dispatch({type: types.EDIT_TODO, id, text});
export const completeTodo = id => dispatch => dispatch({type: types.COMPLETE_TODO, id});
export const clearCompleted = () => dispatch => dispatch({type: types.CLEAR_COMPLETED});
export const showAll = () => dispatch => dispatch({type: types.SHOW_ALL});
export const showActive = () => dispatch => dispatch({type: types.SHOW_ACTIVE});
export const showCompleted = () => dispatch => dispatch({type: types.SHOW_COMPLETED});
View components.number-count.js
import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';
import { connect } from 'ember-redux';
const stateToComputed = state => {
return {
number: state.number
};
};
@toranb
toranb / jedi-for-python.txt
Created Jan 15, 2019
Python for go-to-definition
View jedi-for-python.txt
pip install jedi
then -in your vimrc
```
nmap <Leader>j :call InvokeJumpToByType()<CR>
function! InvokeJumpToByType()
let filetype=&ft
if filetype == 'python'
exe ':call jedi#goto_definitions()'
@toranb
toranb / components.number-count.js
Last active Dec 29, 2018
es2015 class syntax (ember redux)
View components.number-count.js
import Ember from 'ember';
import { connect } from 'ember-redux';
import hbs from 'htmlbars-inline-precompile';
const stateToComputed = state => ({
number: state.number
});
const dispatchToActions = dispatch => ({
add: () => dispatch({type: 'ADD'})
@toranb
toranb / postgres.txt
Created Dec 23, 2018
First time install of postgres on macOS Mojave
View postgres.txt
1) Install homebrew if you haven't already
https://brew.sh/
2) Install postgres
brew install postgresql
3) Start the database
@toranb
toranb / wait-for-redux.js
Last active Nov 1, 2018
custom ember helper to wait for redux to be in a given state
View wait-for-redux.js
import { Promise } from 'rsvp';
import { next } from '@ember/runloop';
import { registerWaiter } from '@ember/test';
import { getContext } from '@ember/test-helpers';
export async function waitForRedux(key, value) {
return new Promise(async (resolve) => {
let counter = 1;
registerWaiter(() => counter === 0);
const { owner } = getContext();
@toranb
toranb / hydrate_state_from_filesystem.ex
Created Oct 28, 2018
Simple GenServer callback to create a map w/ {key, value} pairs by looking at the filesystem
View hydrate_state_from_filesystem.ex
@impl GenServer
def handle_call({:all}, _timeout, _state) do
{:ok, files} = :file.list_dir(@database)
state =
Enum.map(files, fn (key) ->
value =
case File.read(file_name(@database, key)) do
{:ok, contents} -> :erlang.binary_to_term(contents)
_ -> nil
end
@toranb
toranb / verbose-some.exs
Created Oct 14, 2018
My first implementation of some in elixir
View verbose-some.exs
defmodule MyEnum do
def some([], _func), do: []
def some([head | tail], func) do
case func.(head) do
true ->
true
false ->
case some(tail, func) do
true ->
true
@toranb
toranb / pinned-values-as-params.exs
Last active Sep 27, 2018
showing how pinned values and pattern matching work in elixir
View pinned-values-as-params.exs
defmodule Robot do
def speak(name, phrase) do
fn
(^name) -> "hello! #{name}, #{phrase}"
(_) -> "sorry ... don't know this name"
end
end
end
You can’t perform that action at this time.