Skip to content

Instantly share code, notes, and snippets.

View jkarttunen's full-sized avatar

Juha Karttunen jkarttunen

View GitHub Profile
@melborne
melborne / haskell_sequence.rb
Created July 7, 2011 14:02
Haskell-like Arithmetic Sequence in Ruby
# encoding: UTF-8
class Array
alias __eq__ ===
def ===(other)
if self.size == other.size and any? { |item| item.instance_of? Class }
other = other.to_enum
return all? { |item| item === other.next }
end
__eq__(other)
end
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@heikki
heikki / gist:4030954
Last active November 19, 2015 12:29
Notes for VirtualBox IE setup
https://www.virtualbox.org/wiki/Downloads
https://github.com/xdissent/ievms
For each installed VM:
- Enable copy&paste (Settings -> General -> Advanced -> Shared Clipboard -> Host To Guest)
- Add more video memory (Settings -> Display -> Video -> Video Memory -> 128 MB ?)
- Add Finnish keyboard layout as default and remove others
- Set IE homepage to about:blank
- Disable Windows key http://support.microsoft.com/kb/216893#FixItForMeAlways
- Take snapshot
@benschw
benschw / gist:5516156
Last active December 16, 2015 23:49
AngularJS Breadcrumbs Service
// https://github.com/angular-app/angular-app
angular.module('services.breadcrumbs', []);
angular.module('services.breadcrumbs').factory('breadcrumbs', ['$rootScope', '$location', function($rootScope, $location){
var breadcrumbs = [];
var breadcrumbsService = {};
//we want to update breadcrumbs only when a route is actually changed
//as $location.path() will get updated imediatelly (even if route change fails!)
@lavoiesl
lavoiesl / object.create.js
Created September 20, 2013 18:49
Javascript Object.create() polyfill
// http://jsperf.com/new-vs-object-create-including-polyfill
if (typeof Object.create !== 'function') {
Object.create = function(o, props) {
function F() {}
F.prototype = o;
if (typeof(props) === "object") {
for (prop in props) {
if (props.hasOwnProperty((prop))) {
F[prop] = props[prop];
@eoinkelly
eoinkelly / visualize-stacking-contexts.js
Last active February 7, 2021 08:04
Some console output to help you visualise stacking contexts on a page
/*
Usage:
* Paste this into your dev tools console (or even better as a snippet)
* It will parse the page and find all the things that create a new stacking context
and dump some info about them to the console. It will also outline them on the page.
* This is pretty rough and probably misses heaps of bugs and edge cases.
*/
@staltz
staltz / introrx.md
Last active August 10, 2025 21:23
The introduction to Reactive Programming you've been missing
@chrisveness
chrisveness / base64.js
Last active March 10, 2025 11:51
Encode/decode ASCII string to/from base64
/**
* Encode string into Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648].
* As per RFC 4648, no newlines are added.
*
* Characters in str must be within ISO-8859-1 with Unicode code point <= 256.
*
* Can be achieved JavaScript with btoa(), but this approach may be useful in other languages.
*
* @param {string} str ASCII/ISO-8859-1 string to be encoded as base-64.
* @returns {string} Base64-encoded string.