Skip to content

Instantly share code, notes, and snippets.

@jcla1
jcla1 / gist:1453094
Created December 9, 2011 20:11
MMI of e mod totient(n)
function doLoop(a, b) {
for(i=1; i < window.Infinity; i++){
x = (a * i -1) % b;
if( x === 0 ){
console.log(i)
break;
}
}
}
@jcla1
jcla1 / activity.java
Created January 3, 2012 08:58
Using content providers in Android post
package com.jcla1.android.test.bookmarksgetter;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Browser;
@jcla1
jcla1 / hello_world.cc
Created January 7, 2012 14:47
Exploring the V8 JS engine (Part 1 of 2)
#include <v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
// Create a new context.
Persistent<Context> context = Context::New();
// Enter the created context for compiling and
@jcla1
jcla1 / share_variable_changeable.cc
Created January 8, 2012 13:09
Exploring the V8 JS engine (Part 2 of 2)
#include <v8.h>
using namespace v8;
// This is the variable we are going to share
int x = 15;
// Gets called when the value of x is requested
Handle<Value> XGetter(Local<String> property,
const AccessorInfo& info) {
@jcla1
jcla1 / body.html
Created March 11, 2012 08:36
Web Audio API overview post
<body>
<div id="container">
<canvas height="200" width="500" id="fft"></canvas>
<audio id="audio" src="IO2010.mp3" preload controls></audio>
</div>
<script>
// requestAnim shim layer by Paul Irish
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
@jcla1
jcla1 / codemirror.css
Last active June 24, 2019 23:37
Getting to work with CodeMirror
/* BASICS */
.CodeMirror {
/* Set height, width, borders, and global font properties here */
font-family: monospace;
height: 300px;
}
.CodeMirror-scroll {
/* Set scrolling behaviour here */
overflow: auto;
@jcla1
jcla1 / example.rb
Created October 17, 2012 12:42
ZipPlease Ruby Example
require 'sinatra'
require 'rest_client'
require 'uuid'
require 'json'
# For generating UUIDs
uuid = UUID.new
zipPleaseAPIEndpoint = "http://www.zipplease.com/api/zips"
@jcla1
jcla1 / authinabox.rb
Created November 24, 2012 19:30 — forked from nbrew/authinabox.rb
Single File Data Mapper Authentication for Sinatra
# NAME: authinabox
# VERSION: 1.01 (Dec 27, 2008)
# AUTHOR: Peter Cooper [ http://www.rubyinside.com/ github:peterc twitter:peterc ]
# DESCRIPTION: An "all in one" Sinatra library containing a User model and authentication
# system for both session-based logins OR HTTP Basic auth (for APIs, etc).
# This is an "all in one" system so you will probably need to heavily tailor
# it to your own ideas, but it will work "out of the box" as-is.
# COMPATIBILITY: - Tested on 0.3.2 AND the latest rtomayko Hoboken build! (recommended for the latter though)
# - NEEDS DataMapper!
# - Less work needed if you use initializer library -- http://gist.github.com/40238
@jcla1
jcla1 / drawArrow.js
Created December 18, 2012 20:45
Drawing an arrow in JS can be hard!
function drawArrow(x, y, w, h, rot) {
ctx.save();
ctx.translate((x + w / 2), (y + h / 2));
ctx.rotate(rot);
ctx.translate(-(x + w / 2), -(y + h / 2));
ctx.translate(x, y);
a = 0;
@jcla1
jcla1 / Arrow.coffee
Created December 19, 2012 17:32
Pointing Arrow
class Arrow
constructor: (x, y, w, h, rot)->
@x = x
@y = y
@w = w
@h = h
@rot = rot
pointTo: (x, y) ->
m_y = @y - y