Skip to content

Instantly share code, notes, and snippets.

View jaf7's full-sized avatar

Anthony Fields jaf7

View GitHub Profile
@jaf7
jaf7 / index.md
Created May 2, 2018 18:09 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@jaf7
jaf7 / Bluecore_assessment.js
Created August 10, 2018 18:30
Bluecore Coding Assessment
// Question 1
function incorrectChars( input, output) {
const inputString = input.toLowerCase();
const outputString = output.toLowerCase();
const multiple = outputString.length / inputString.length;
let incorrect = 0;
for ( let i = 0; i < outputString.length - inputString.length; i + inputString.length ) {
const outputSubString = outputString.substring(i, i+inputString.length);
console.log('outputSubString: ' + outputSubString)
@jaf7
jaf7 / pyenv+virtualenv.md
Created December 13, 2018 22:40 — forked from eliangcs/pyenv+virtualenv.md
Cheatsheet: pyenv, virtualenvwrapper, and pip

Cheatsheet: pyenv, virtualenvwrapper, and pip

Installation (for Mac OS)

Install pyenv with brew

brew update
brew install pyenv
@jaf7
jaf7 / .phoenix.js
Created December 20, 2018 16:21 — forked from josser/.phoenix.js
Phoenix config
'use strict';
var keys = [];
var controlAlt = [ 'ctrl', 'alt' ];
var margin = 0;
var increment = 0.1
function log() {
Phoenix.log(JSON.stringify(arguments[0], true, 2));
}
@jaf7
jaf7 / reactScrollPositionY.js
Created February 15, 2019 19:47 — forked from agm1984/reactScrollPositionY.js
How to get Y scroll position in React
import React, { Component } from 'react'
import UserDetails from './UserDetails'
/**
* This utility function allows function calls to be debounced.
* @param {Function} func Function that requires debouncing
* @param {Number} wait Wait time in milliseconds between successive invocations
*/
const debounce = (func, wait) => {
let timeout
@jaf7
jaf7 / decorator_of_cache_per_user.py
Created February 23, 2019 01:54 — forked from caot/decorator_of_cache_per_user.py
decorator of cache per user in python and django
from django.core.cache import cache as core_cache
'''
refer:
http://stackoverflow.com/questions/20146741/django-per-user-view-caching
https://djangosnippets.org/snippets/2524/
'''
def cache_key(request):
@jaf7
jaf7 / react-table-component.js
Created March 4, 2019 01:20 — forked from ChaseWest/react-table-component.js
React Table Component for creating a very basic html table
var Table = React.createClass({
render: function render() {
var _self = this;
var thead = React.DOM.thead({},
React.DOM.tr({},
this.props.cols.map(function (col) {
return React.DOM.th({}, col);
})));
@jaf7
jaf7 / states_hash.json
Created June 15, 2019 21:42 — forked from mshafrir/states_hash.json
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@jaf7
jaf7 / stream_csv.py
Created July 19, 2019 00:43 — forked from jerel/stream_csv.py
Easily export a massive dataset from Django to the browser as a streaming CSV file
import csv
from StringIO import StringIO
from django.http import StreamingHttpResponse
class StreamCSV(object):
def __init__(self):
self._buffer = StringIO()
self._writer = csv.writer(self._buffer)
@jaf7
jaf7 / cities.ts
Created August 16, 2019 22:11 — forked from larkintuckerllc/cities.ts
new-1
import Dexie from 'dexie';
import citiesJson from './cities.json';
const delay = () =>
new Promise(resolve => {
setTimeout(() => {
resolve('');
}, 1000);
});