Skip to content

Instantly share code, notes, and snippets.

View ivpusic's full-sized avatar
👨‍💻

Ivan Pusic ivpusic

👨‍💻
View GitHub Profile
@sylr
sylr / postgres-9.5-sharding.sh
Last active June 11, 2019 21:23
Postgresql 9.5 sharding example
echo master shard_{0,1,2,3} | xargs -n1 /usr/local/bin/dropdb -p 6432 -h /tmp -U postgres
echo master shard_{0,1,2,3} | xargs -n1 /usr/local/bin/createdb -p 6432 -h /tmp -U postgres
for a in {0..3}; do
echo "
CREATE TABLE users (id serial PRIMARY KEY, username TEXT NOT NULL);
ALTER SEQUENCE users_id_seq INCREMENT BY 4 RESTART WITH $a;
" | /usr/local/bin/psql -p 6432 -h /tmp -U postgres -d shard_$a;
done
@staltz
staltz / introrx.md
Last active November 14, 2024 11:27
The introduction to Reactive Programming you've been missing
@tito
tito / poll_delegate_objus.py
Created February 1, 2014 15:19
Which delegate usage would be the best to have in Pyobjus ?
# Solution 1
# original solution proposed in the PR
# pro: easy declaration
# cons: instanciation is a little bit hard to write
# possible method conflict with multiple protocols
class MyObjcDelegate:
def connection_didFailWithError_(self, connection, error):
print("Protocol method got called!!", connection, error)
@jkneb
jkneb / Gruntfile.js
Created July 24, 2013 16:48
grunt-ember-handlebars plugin config for the Gruntfile + package.json. You'll have to update the Gruntfile with YOUR correct path to templates files. 1. Run `npm install` 2. Run `grunt` or `grunt watch`
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
ember_handlebars: {
options: {
processName: function(filePath) {
var shortFilePath = filePath.replace(/assets\/js\/app\/templates\//, '').replace('.hbs', '');
return shortFilePath;
},
@tito
tito / pointer.py
Created July 2, 2013 15:37
Exploration of ctypes to get C memory address from a ctypes object, and reuse the memory address to get back a ctypes object
import ctypes
class Point(ctypes.Structure):
_fields_ = (
("x", ctypes.c_int),
("y", ctypes.c_int))
p1 = Point(23, 4)
print 'Original point is', (p1.x, p1.y)
@ruiwen
ruiwen / fb-angular.js
Last active July 5, 2017 10:40
Wrapping and initialising the Facebook SDK with Angular JS
// Facebook SDK
angular.module('facebook', [])
.directive('fb', ['$FB', function($FB) {
return {
restrict: "E",
replace: true,
template: "<div id='fb-root'></div>",
compile: function(tElem, tAttrs) {
return {
post: function(scope, iElem, iAttrs, controller) {
@tcr
tcr / gist:4416956
Last active November 29, 2017 03:38
Make a callable() object in all browsers and Node.js
if (!Object.__proto__) {
var sandbox = function () {
// create an <iframe>
var iframe = document.createElement("iframe");
iframe.style.display = "none";
document.documentElement.appendChild(iframe);
return frames[frames.length - 1];
}
var iframe = sandbox();
@jellybeansoup
jellybeansoup / cltools.sh
Last active March 7, 2024 22:57
Install Autoconf and Automake on OS X Mountain Lion
#!/bin/sh
##
# Install autoconf, automake and libtool smoothly on Mac OS X.
# Newer versions of these libraries are available and may work better on OS X
#
# This script is originally from http://jsdelfino.blogspot.com.au/2012/08/autoconf-and-automake-on-mac-os-x.html
#
export build=~/devtools # or wherever you'd like to build
@mattratleph
mattratleph / vimdiff.md
Last active October 16, 2024 17:26 — forked from roothybrid7/vimdiff_cheet.md
vimdiff cheat sheet

vimdiff cheat sheet

##git mergetool

In the middle file (future merged file), you can navigate between conflicts with ]c and [c.

Choose which version you want to keep with :diffget //2 or :diffget //3 (the //2 and //3 are unique identifiers for the target/master copy and the merge/branch copy file names).

:diffupdate (to remove leftover spacing issues)

:only (once you’re done reviewing all conflicts, this shows only the middle/merged file)

@domenic
domenic / promises.md
Last active October 13, 2024 22:51
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.