Skip to content

Instantly share code, notes, and snippets.

View kosmikko's full-sized avatar

Mikko Lehtinen kosmikko

  • Applifier
  • Helsinki, Finland
View GitHub Profile
On OSX Yosemite and above, in a terminal window:
1. Switch to the root user.
$ sudo su -
2. Create a Dummynet pipe that represents a slow, unreliable network:
# dnctl pipe 1 config bw 10Kbit/s delay 300 plr 0.1 noerror
@kosmikko
kosmikko / osx.md
Last active February 17, 2017 09:19
OSX shell commands

Prevent sleep for 1 hour:

caffeinate -u -t 3600

Screensaver Immediate Lock

Status

defaults read com.apple.screensaver askForPasswordDelay

Enable (Default)

@kosmikko
kosmikko / rpop_nonmatching.lua
Last active February 3, 2017 11:42
Redis script to pop the last element from LIST_KEY that doesn't match SEARCH arg
-- pop the last element from LIST_KEY that doesn't match SEARCH arg
local LIST_KEY = KEYS[1]
local SEARCH = ARGV[1]
-- avoid the expensive LRANGE by peeking the last element
local last = redis.call('LINDEX', LIST_KEY, -1)
if not (string.find(last, SEARCH)) then
redis.call('RPOP', LIST_KEY)
return last
end
@kosmikko
kosmikko / credits.js
Last active January 21, 2016 10:01
Credits transfer (find issues with it)
function transferCredits(from, to, amt) {
var fromAccount = db.game_accounts.findOne({"name": from},{"credits": 1});
var toAccount = db.game_accounts.findOne({"name": to},{"credits": 1});
db.game_accounts.update({name: from}, {$set: {credits: fromAccount.credits - amt}});
db.game_accounts.update({name: to}, {$set: {credits: toAccount.credits + amt}});
}
db.game_accounts.insert({name: "John", credits: 1000});
db.game_accounts.insert({name: "Jane", credits: 1000});
@kosmikko
kosmikko / robodog.js
Created January 20, 2016 09:42
robodog
class GameObject {
constructor(name) {
this.name = name;
}
sayName() {
console.log(`Hi, I am ${this.name}`);
}
}
package main
import (
"log"
"reflect"
"strings"
)
type RoleAccess struct {
RoleName string
@kosmikko
kosmikko / gist:00d6567ad74c02d961f8
Created March 4, 2015 13:10
Use netrc to allow "go get" for private repos
@kosmikko
kosmikko / css_resources.md
Created June 2, 2014 11:01 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.

Libraries

  • 960 Grid System - An effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.
  • Compass - Open source CSS Authoring Framework.
  • Bootstrap - Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
  • Font Awesome - The iconic font designed for Bootstrap.
  • Zurb Foundation - Framework for writing responsive web sites.
  • SASS - CSS extension language which allows variables, mixins and rules nesting.
  • Skeleton - Boilerplate for responsive, mobile-friendly development.

Guides

@kosmikko
kosmikko / javascript_resources.md
Created June 2, 2014 11:01 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage