Skip to content

Instantly share code, notes, and snippets.

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

Huascar Sanchez hsanchez

I may be slow to respond.
View GitHub Profile
@hsanchez
hsanchez / algorithm2e_template
Last active August 29, 2015 14:25 — forked from lgylym/algorithm2e_mapreduce
algorithm template using algorithm2e
\begin{algorithm}[H]
\SetKwFor{ForEach}{for each}{do}{end}%separate foreach with a space
\SetArgSty{textrm} %do not automatically use italic in arguments
\SetKwInOut{KwInit}{Initialization}
\SetKwFunction{Map}{Map}
\SetKwFunction{Reduce}{Reduce}
\SetKwProg{myproc}{Procedure}{}{}
\DontPrintSemicolon % Some LaTeX compilers require you to use \dontprintsemicolon instead
\KwIn{}
\KwOut{}
int m, n;
boolean[][] graph;
boolean seen[];
int matchL[]; //What left vertex i is matched to (or -1 if unmatched)
int matchR[]; //What right vertex j is matched to (or -1 if unmatched)
int maximumMatching() {
//Read input and populate graph[][]
//Set m to be the size of L, n to be the size of R
Arrays.fill(matchL, -1);

jquery.scrollLock.js

Useful for when a blocking user experience is needed (in my case, didn't want people unwittingly loosing their place by scrolling while a modal required their attention): $.scrollLock() locks the body in place, preventing scroll until it is unlocked.

// Locks the page if it's currently unlocked
$.scrollLock();

// ...or vice versa

Stopping a Jekyll server with ctrl-z can cause issues as the process is not stopped fully. To kill it:

$ lsof -wni tcp:4000
$ kill -9 <PID of process>

And next time, use crtl-c to stop.

package com.agilogy.spray.cors
import spray.http.{HttpMethods, HttpMethod, HttpResponse, AllOrigins}
import spray.http.HttpHeaders._
import spray.http.HttpMethods._
import spray.routing._
// see also https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
trait CORSSupport {
this: HttpService =>
function simpleSearch(text, str) {
var matches = [];
for (var i = 0; i <= text.length; i++) {
if (matchesAtIndex(i, text, str)) {
matches.push(i);
}
}
return matches;
}
package models
import anorm._
import anorm.SqlParser._
import play.api.db.DB
import play.api.Play.current
case class Destination(id: Long, originalUrl: String, shortUrlHash: String)
object Destination {
@hsanchez
hsanchez / bijective.rb
Last active August 29, 2015 14:07 — forked from zumbojo/bijective.rb
# Simple bijective function
# Basically encodes any integer into a base(n) string,
# where n is ALPHABET.length.
# Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047
ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//)
# make your own alphabet using:
# (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join
#!/Users/dustyeike/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
require "rubygems"
require "test/unit"
require "date"
EPOCH = Date.new(1970, 1, 1)
#
# Returns the number of seconds from the epoch to date
def epoch_seconds date
@hsanchez
hsanchez / 0_reuse_code.js
Created July 30, 2014 00:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console