Skip to content

Instantly share code, notes, and snippets.

Avatar

Isaac kavunshiva

View GitHub Profile
View playing_with_promises.js
let someBoringPromise = new Promise((winner, loser) => winner())
let anotherBoringPromise = new Promise((winner, loser) => loser())
let someLessBoringPromise = new Promise((winner, loser) => winner(console.log("cat")))
let anotherLessBoringPromise = new Promise((winner, loser) => loser(console.log("dog")))
let someBoringPromiseWithPotential = new Promise((winner, loser) => winner("cat"))
@kavunshiva
kavunshiva / positions_controller.rb
Last active Jul 11, 2017
persisting position to a database
View positions_controller.rb
class Api::V1::PositionsController < ApplicationController
before_action :authorize_device!
def index
positions = Position.where(device_id: params[:id]).order(time: :desc)
render json: positions
end
def create
position = Position.new(
@kavunshiva
kavunshiva / randomAsciiGenerator.js
Last active Nov 13, 2018
Generate a random string of ASCII characters
View randomAsciiGenerator.js
const generateRandomAsciiString = (len, cap=false, lower=false, num=false, special=false) => {
let str = '';
const includesCap = str => !![...Array(26)]
.map((n, i) => String.fromCharCode(i + 65))
.filter(c => str.includes(c)).length;
const includesLower = str => !![...Array(26)]
.map((n, i) => String.fromCharCode(i + 97))
.filter(c => str.includes(c)).length;
const includesNum = str => !![...Array(10)]
.map((n, i) => String.fromCharCode(i + 48))
@kavunshiva
kavunshiva / nationbuilderCrud.js
Last active Jun 7, 2019
nationbuilder sample basic CRUD
View nationbuilderCrud.js
// EVENTS
let event;
// create event
const createEvent = (newEvent, nationSlug, siteSlug, accessToken) => {
return fetch(`https://${nationSlug}.nationbuilder.com/api/v1/sites/${siteSlug}/pages/events?access_token=${accessToken}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
You can’t perform that action at this time.