Skip to content

Instantly share code, notes, and snippets.

@bspaulding
bspaulding / require.js
Created November 22, 2011 20:26
CommonJS Modules Implementation in Pure JS
var exports = {};
var module = {};
function require(id) {
if ( 'undefined' === typeof arguments.callee.require_stack ) { arguments.callee.require_stack = []; }
var require_stack = arguments.callee.require_stack;
if ( 'undefined' === typeof arguments.callee.modules ) { arguments.callee.modules = {}; }
var modules = arguments.callee.modules;
// if currently requiring module 'id', return partial exports
@xslim
xslim / AppDelegate.m
Created October 8, 2012 22:41
AFIncrementalStore with If-Modified-Since hack
// Connecting AFIncrementalStore & MagicRecord
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
PDDebugger *debugger = [PDDebugger defaultInstance];
[debugger connectToURL:[NSURL URLWithString:@"ws://localhost:9000/device"]];
[debugger enableNetworkTrafficDebugging];
[debugger forwardAllNetworkTraffic];
[debugger enableCoreDataDebugging];
@sergeyzenchenko
sergeyzenchenko / Instructions.md
Created November 29, 2012 16:13 — forked from alloy/Instructions.md
Run iOS unit tests (in a Xcode workspace) when a file changes and *only* those tests related to the changed file. Also trims otest output and colors test results.
#include <dispatch/dispatch.h>
typedef void (^MHChannelsBlock)(id sender, NSDictionary *dictionary);
/*!
* A "channel" is like a private NSNotificationCenter between just two objects
* (although more are possible).
*
* Instead of making your objects, such as two view controllers, communicate
package your.awesome.app;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements ImageCache {
public LruBitmapCache(int maxSize) {
super(maxSize);
@gak
gak / fish-prompt.sh
Last active February 4, 2022 18:34
My custom fish prompt code explained at http://geraldkaszuba.com/tweaking-fish-shell/
function _common_section
printf $c1
printf $argv[1]
printf $c0
printf ":"
printf $c2
printf $argv[2]
printf $argv[3]
printf $c0
printf ", "
@dodyg
dodyg / gist:5823184
Last active March 29, 2024 03:59
Kotlin Programming Language Cheat Sheet Part 1

#Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

@branneman
branneman / better-nodejs-require-paths.md
Last active June 12, 2024 02:40
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@nrocine
nrocine / Installation of Kafka
Created January 9, 2014 18:15
Installation of Kafka on Vagrant Ubuntu Base Box. We may not want to use the ppa:webupd8team/java PPA to install HotSpot JDK. http://kafka.apache.org/documentation.html#quickstart
mkdir ~/kafka
vagrant init metrics http://files.vagrantup.com/precise64.box
vagrant up
vagrant ssh
sudo apt-get update
sudo apt-get install curl
sudo apt-get install python-software-properties
@pfrazee
pfrazee / gist:8949363
Last active August 22, 2023 12:31
In-Application Sandboxing with Web Workers

In-Application Sandboxing with Web Workers

A design rationale.

For the past fews years, the Web has been shifting control to the client. Given the limitations of remote services, developers are now looking for ways to "unhost" static applications – that is, break the dependency on remote servers while still using the Web platform.

One untapped technology for client-side control is the Web Worker Sandbox. This API lets the Page load, execute, and destroy separate Worker threads which use their own Virtual Machines. By using Worker Sandboxes to drive behavior, the Web can give users the choice of which software they run together, shifting development from a centralized SaaS model into a distributed and free (as in freedom) script-sharing model.

Worker Sandboxes can Execute Arbitrary Code