Skip to content

Instantly share code, notes, and snippets.

View codecakes's full-sized avatar
💭
I may be slow to respond.

codecakes codecakes

💭
I may be slow to respond.
View GitHub Profile
@codecakes
codecakes / printYN.html
Created April 28, 2016 08:12
Write a program that listens for a keyup event. In the handler, check which key was released. If it was “Y”, log the word “Yes”. If it was “N” log the word “No”. If it was any other key, log, “I don’t understand.”
<html>
<head>
</head>
<body>
<script async src="//jsfiddle.net/3M6Xt/31/embed/js,html,css,result/dark/"></script>
</body>
</html>
@codecakes
codecakes / asyncScriptLoad.js
Created May 18, 2016 20:30
Dynamic Async Script Loading for my own pleasure and use and whatever
// http://www.html5rocks.com/en/tutorials/speed/script-loading/
// how about that?
// first load all dependent libs
let loadScripts = ( () => {
let
scripts = [
// 'https://code.jquery.com/jquery-2.2.3.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js',
'https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone-min.js'
],
@codecakes
codecakes / nth_root.py
Created June 4, 2016 11:40
Find the nth root of a Number
O(1) approximate solution
from math import floor, log
nth_root = lambda num, n: floor(round(n**(log(num, n) * 1./n), 1))
@codecakes
codecakes / gulpfile.js
Created June 6, 2016 13:16 — forked from danharper/gulpfile.js
New ES6 project with Babel, Browserify & Gulp
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
@codecakes
codecakes / html_decoder.py
Created June 18, 2016 09:13
If you had a filter to filter all htm incoming raw string using BeautifulSoup
from __future__ import unicode_literals
from BeautifulSoup import BeautifulStoneSoup
def html_decoder(s):
return BeautifulStoneSoup(s, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
if __name__ == "__main__":
s = "U.S. Adviser&#8217;s Blunt Memo on Iraq: Time &#8216;to Go Home&#8217;"
print html_decoder(s)
@codecakes
codecakes / max_binary.js
Created June 22, 2016 13:49
Given a list of unsorted integers, find maximum binary string or maximum integer whichever comes highest
fn = (l, lo, hi, b) => {
if (lo<hi) {
mid = parseInt((lo+hi)/2);
fn(l, lo, mid, b);
fn(l, mid+1, hi, b);
}
else {
let c = l[lo].toString(2).match(/1+/gi).join('').length;
console.log(c, l[lo]);
if (b[0] < l[lo]) b[0] = l[lo];
@codecakes
codecakes / url_param.js
Created August 6, 2016 21:08
Simple Url Parameter extraction from DOM
"use strict";
let paramRegex = /([a-zA-Z0-9]+\=[a-zA-Z0-9]+)/ig;
location.search.match(paramRegex);
@codecakes
codecakes / install-libsodium.sh
Created August 10, 2016 12:42 — forked from jonathanpmartins/install-libsodium.sh
Install Libsodium on Ubuntu 14.04.3 LTS Trusty
#!/bin/bash
sudo add-apt-repository ppa:chris-lea/libsodium;
sudo echo "deb http://ppa.launchpad.net/chris-lea/libsodium/ubuntu trusty main" >> /etc/apt/sources.list;
sudo echo "deb-src http://ppa.launchpad.net/chris-lea/libsodium/ubuntu trusty main" >> /etc/apt/sources.list;
sudo apt-get update && sudo apt-get install libsodium-dev;
@codecakes
codecakes / gevent_sock_server.py
Last active December 30, 2016 17:20
a simple echo server gevent socket sock_stream that connects with 5 clients and echoes back the message
import gevent
from gevent.server import StreamServer as gStream
from gevent import socket as gsocket
from gevent import select as gselect
from collections import deque, defaultdict
def divide(alist, lo, hi, fn, *args):
if lo < hi:
mid = (hi-lo)/2 + lo
divide(alist, lo, mid, fn, *args)
@codecakes
codecakes / model.ex
Created January 26, 2017 20:05 — forked from narrowtux/model.ex
Recursive models with ecto
defmodule Model do
schema "models" do
field :foo, :string
has_many :children, Model, foreign_key: :parent_id
belongs_to :parent, Model, foreign_key: :parent_id
end
@doc """
Recursively loads parents into the given struct until it hits nil
"""