Skip to content

Instantly share code, notes, and snippets.

@shangaslammi
shangaslammi / hello-ski.hs
Created August 23, 2012 16:53
Hello World using SKI combinator calculus
s x y z = x z (y z)
k x y = x
i = s k k
c = s (s (k (s (k s) k)) s) (k k)
b = s (k s) k
hello =
s(s(k s)(s(k k)(s(k s)(s(k(s(k s)))(s(s(k s)(s(k k)(s(k b)i)))(k(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s
b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(c k))))))))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))(s(s(k s)(s(k k)(s(k s)(s(k(s(k s)))(s(s(k s)(s(k k)(s(k b)i)))(k(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s
@elclanrs
elclanrs / refreshCss.js
Last active October 11, 2015 15:58
Auto-refresh CSS in browser
// Copy paste in browser console
// F5 to stop interval
setInterval(function () {
[].filter.call(document.querySelectorAll('link'), function(el) {
return !/google|lorempixel/.test(el.href);
}).forEach(function (el) {
var href = el.href,
date = '?' + new Date().getTime();
el.href = /\?/.test(href) ? href.replace(/\?.+/, date) : href + date;
});
@elclanrs
elclanrs / sRegExpWithUnicode.js
Created October 15, 2012 08:13
Super Regex, interpolate variables in regular expressions with unicode
// Super RegExp
// @param regex A regular expression as literal or as string
// @param obj And object containing the values to replace inside the regex
// Usage: var regex = sRegExp( /Hello #{a}/, { a: 'World' } )
function sRegExp( regex, obj ) {
regex = regex.toString();
var newRegex = regex.replace(/(^\/|\/$|\/([igm]+)$)/g, '')
.replace( /#\{(\w+)\}/g, function( a,b ) { return obj[b]; });
var mods = regex.match( /\/([igm]+)$/ );
return new RegExp( newRegex, mods ? mods[1] : '' );
@sshtmc
sshtmc / ubuntu-configure-sendmail-with-gmail
Created October 25, 2012 12:24
Ubuntu sendmail using smtp.gmail.com
#!/bin/bash
HOST=$(hostname)
function install_postfix() {
echo | sudo debconf-set-selections <<__EOF
postfix postfix/root_address string
postfix postfix/rfc1035_violation boolean false
postfix postfix/mydomain_warning boolean
postfix postfix/mynetworks string 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
@elclanrs
elclanrs / jquery.onlyChars.js
Created October 30, 2012 02:39
onlyChars: allow only certain characters in an input
$.fn.onlyChars = function( re ) {
return this.keypress(function( e ) {
return re.test( String.fromCharCode( e.which ) ) ||
!!~[ 8,9,13,16,17,37,38,39,40 ].indexOf( e.which ); // Exclude modifier keys
});
};
// Usage:
// Keep in mind that the regex tests only a single character
$('input').onlyChars( /\d/ ); // only numbers
@elclanrs
elclanrs / checkType.js
Created December 18, 2012 10:31
checkType: Check type of each param in a function and throw type error if it doesn't match as expected.
function typeOf( obj ) {
return {}.toString.call( obj ).match(/\s(\w+)/)[1].toLowerCase();
}
function checkTypes( args, types ) {
args = [].slice.call( args );
for ( var i = 0; i < types.length; ++i ) {
if ( typeOf( args[i] ) != types[i] ) {
throw new TypeError( 'param '+ i +' must be of type '+ types[i] );
}
@elclanrs
elclanrs / demo.md
Last active December 10, 2015 20:28
jQuery news ticker
@ngauthier
ngauthier / README.md
Last active December 8, 2023 13:56
install ruby 2.0.0-p0 on ubuntu
@mkuklis
mkuklis / gist:5294248
Last active September 7, 2021 21:39
auto curry in JavaScript
function toArray(args) {
return [].slice.call(args);
}
function autocurry(fn) {
var len = fn.length;
var args = [];
return function next() {
args = args.concat(toArray(arguments));
return (args.length >= len) ?
@ChangJoo-Park
ChangJoo-Park / gist:5443017
Last active January 29, 2019 20:55
# Ubuntu 13.04 , linux mint install RVM with Ruby 2.0.0-p353 , Rails 4.0.0
# If you meet install errors, see abid-hussain's comment
sudo apt-get --force-yes install build-essential openssl libreadline6 libreadline6-dev curl git-core \
zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev \
libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison
&&
\curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled