Skip to content

Instantly share code, notes, and snippets.

View waynew's full-sized avatar
💭
Making the world a little Saltier - one grain at a time

Wayne Werner waynew

💭
Making the world a little Saltier - one grain at a time
View GitHub Profile
@kennethreitz
kennethreitz / oh-god.py
Created November 24, 2009 16:32
My first python script from 4 years ago. Wow.
def main():
import os, time
menu_selection = 0
while menu_selection != 5:
clear_screen()
mainmenu()
if menu_selection == 1:
clear_screen()
print_instructions()
elif menu_selection == 2:
@max-mapper
max-mapper / readme.md
Created September 28, 2011 02:01
SLEEP - syncable.org

Your API does REST, but can it SLEEP?

SLEEP (Syncable Lightweight Event Emitting Persistence) is an emerging standard for distributed data sync using HTTP and JSON. A generalized version of CouchDB's much lauded built-in replication, SLEEP extends the REST architecture to define a way in which databases can offer syncable JSON APIs that foster open data innovation by allowing developers to replicate entire databases over the net.


SLEEP comes from the Apache CouchDB project which is now widely known for it's multi-master streaming HTTP + JSON replication. This is possible in part because of the CouchDB _changes feed, which is a particular API that lets you see if there have been any changes made to the database since last time you synchronized. CouchDB can efficiently implement the _changes feed because of one subtle difference between it and most other databases: it stores a history of all changes that happen to the database, including deletes.

If you synchronize data from a remote source and then the

@mattt
mattt / UTTypeForImageData.m
Created March 27, 2014 23:19
A quick function for determining an image's file type by its first couple of bytes
@import MobileCoreServices;
static CFStringRef UTTypeForImageData(NSData *data) {
const unsigned char * bytes = [data bytes];
if (data.length >= 8) {
if (bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E && bytes[3] == 0x47 && bytes[4] == 0x0D && bytes[5] == 0x0A && bytes[6] == 0x1A && bytes[7] == 0x0A) {
return kUTTypePNG;
}
}
@ralt
ralt / readme.md
Last active September 7, 2016 18:57
Lossless token change

Some information:

  • fingerprint is 5 bytes, and is at position 0 on device. There's no fingerprint on user file.
  • a token is 128 bytes

  • on device, fseek to position 133 (i.e. after the fingerprint + token). Write the fingerprint + the old token. If power is cut during the writing, or after, the next login will be fine. (successful login if there's a failure = old token at pos 5 on device + old token at pos 0 on user file)

  • once the old token is written, fseek back to position 5 (right after the fingerprint), and write the new token. If power is cut during the writing or after, the next login will fail, look for a fingerprint, if there is, compare with the token after. Since it's the old one, the login will be fine. (successful login if there's a failure = old token at pos 138 on device + old token at position 0 on user file)

@avafloww
avafloww / PhpJava.java
Last active June 13, 2024 07:36
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
@subfuzion
subfuzion / README.md
Created November 7, 2017 18:33 — forked from boneskull/README.md
example of how to debug mocha v4 if hanging

Here's an example of how to debug Mocha v4 if it hangs.

Ensure you're using a Node.js 8 or newer (or any version with async_hooks support).

If you run your test, you'll notice it hangs:

$ mocha test.js