Skip to content

Instantly share code, notes, and snippets.

View andris-silis's full-sized avatar

Andris Sīlis andris-silis

View GitHub Profile
@andris-silis
andris-silis / Flask SSL-only Session Interface
Last active December 20, 2015 05:18
SSL-only session interface for Flask. Sets session cookie only on SSL connection to prevent session hijacking. Sessions will not work on unsecured connections. Need to implement additional secondary session for insecure connection if flashes or something is needed.
# Usage:
app = Flask()
app.session_interface = SecureCookieSSLOnlySessionInterface()
from flask.sessions import SecureCookieSessionInterface
from flask import request
class SecureCookieSSLOnlySessionInterface(SecureCookieSessionInterface):
"""The SSL cookie session interface. Sets cookie only on SSL connections.
// Make it Nasty
function increment (i) {
i ^= (i & ~-~i) | (~i & -~i)
return i
}
@thebyrd
thebyrd / magicMethod.js
Last active December 19, 2015 05:49
Adds jQuery style getters and setters to a given constructor function.
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
}
var getParamNames = function (func) {
var funStr = func.toString()
return funStr.slice(funStr.indexOf('(')+1, funStr.indexOf(')')).match(/([^\s,]+)/g)
}
@8bitDesigner
8bitDesigner / 1.md
Last active January 2, 2025 20:52
Git post-merge hook which, when you run `git merge` or `git pull` will then `bundle` if the project's Gemfile changed, or `npm install` if the project's package.json changed.Inspired and based off of https://gist.github.com/bumi/5706550

Make bundleing and npm installing easy

This repo has some handy handy hooks to run bundle or npm install whenever you:

  • git checkout a new branch with a different Gemfile or package.json
  • git pull a change to Gemfile or package.json

How can I has this!!?

  1. git clone https://gist.github.com/5869846.git hooks && cd hooks && chmod +x install
@ragingwind
ragingwind / Backend Architectures Keywords and References.md
Last active March 21, 2025 15:01
Backend Architectures Keywords and References
# MAC manipulators
alias random_mac='sudo ifconfig en0 ether `openssl rand -hex 6 | sed "s/\(..\)/\1:/g; s/.$//"`'
alias restore_mac='sudo ifconfig en0 ether YOUR_ORIGINAL_MAC_ADDRESS_GOES_HERE'
@ljos
ljos / cocoa_keypress_monitor.py
Last active August 12, 2024 17:34
Showing how to listen to all keypresses in OS X through the Cocoa API using Python and PyObjC
#!/usr/bin/env python
#
# cocoa_keypress_monitor.py
# Copyright © 2016 Bjarte Johansen <[email protected]>
#
# The MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# “Software”), to deal in the Software without restriction, including
@andris-silis
andris-silis / backbone.js-sync-setTimeout
Created April 27, 2012 08:16
extended backbone.js sync function. uses setTimeout to batch multiple saves on one model in one http request.
// decreases request count on rapid-fire one model saves
// extended backbone.js sync function. uses setTimeout to batch multiple saves on one model in one http request.
// if client side needs immediate answer from server for changes in model attributes,
// pass { immediate: true } in model save options if { wait: true } is not used already.
Backbone._sync=Backbone.sync
Backbone.sync = function(method, model, options){
var maxResetCount=5 // how many times to delay save
var saveBufferSize=3000 // for how many microseconds save is delayed
var immediate=options['wait'] || options['immediate'] || false