Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
int main(void) {
unsigned char *p = "$123\r\n";
int len = 0;
p++;
while(*p != '\r') {
len = (len*10)+(*p - '0');
p++;
#!/usr/bin/tclsh8.5
#
# Usage: git-unmerged branch1 branch2
#
# Shows all the non-common commits in the two branches, where non-common
# commits means simply commits with a unique commit *message*.
proc getlog branch {
lrange [split [exec git log $branch --oneline] "\n"] 0 400
}
@mislav
mislav / procs-vs-lambda.md
Last active March 26, 2021 18:34
Jim Weirich on the differences between procs and lambdas in Ruby

Jim Weirich:

This is how I explain it… Ruby has Procs and Lambdas. Procs are created with Proc.new { }, lambdas are created with lambda {} and ->() {}.

In Ruby 1.8, proc {} creates lambda, and Ruby 1.9 it creates procs (don't ask).

Lambdas use method semantics when handling parameters, procs use assignment semantics when handling parameters.

This means lambdas, like methods, will raise an ArgumentError when called with fewer arguments than they were defined with. Procs will simply assign nil to variables for arguments that were not passed in.

@jehiah
jehiah / iphone_messages_dump.py
Last active September 28, 2020 03:53
Script to dump out messages to csv from an iPhone Backup sqlite file
# Copyright Jehiah Czebotar 2013
# http://jehiah.cz/
import tornado.options
import glob
import os
import sqlite3
import logging
import datetime
import csv
@johnl
johnl / cowstat.rb
Created November 27, 2012 19:49
Display info about ram shared between Linux processes
#!/usr/bin/env ruby
require 'ostruct'
class LinuxProcess < OpenStruct
def initialize(args)
super
read_status!
end
@mislav
mislav / geoip_service.rb
Created September 3, 2012 11:48
Simple GeoIP service class using freegeoip.net and Faraday
require 'faraday_middleware'
require 'hashie/mash'
# Public: GeoIP service using freegeoip.net
#
# See https://github.com/fiorix/freegeoip#readme
#
# Examples
#
# res = GeoipService.new.call '173.194.64.19'
@bharrisau
bharrisau / README
Created August 19, 2012 06:14
SMF Manifest to bring up IPv6 on SmartOS
Need to open /usbkey/config and add
admin_v6_ip=xx:xx:xx/xx
admin_v6_gateway=yy:yy:yy
place ipv6 in /opt/custom/smf
place ipv6.xml in /opt/custom/scripts
@mislav
mislav / initialize_spellcheck.rb
Created August 18, 2012 15:32
Raise error if "initialize" method name is misspelled
# Public: Implementation of "Strike a match" algorithm for calculating
# similarity between strings.
#
# http://www.catalysoft.com/articles/StrikeAMatch.html
#
# Examples
#
# checker = StringSimilarityChecker.new('Quick brown fox')
#
# checker =~ 'quick brown ox' #=> true
/****************************************************************************
**
*F hash_dos.c Stuff 1.00 2012-06-06 ms
**
** This small program demonstrates that a multiplicative hash function
** CANNOT be secured against denial-of-service attacks using a initial seed
** value.
**
** That is because two strings <str1> and <str2> of the same length that
** hash to the same value (i.e. produce a collision) for ONE seed will
#include <stdio.h>
int main(void) { /* required by this strange BASIC compiler... */
/* BASIC starts here... */
l10: printf("Hello World\n");
l20: goto l10;
} /* Again, without this it does not work. L4m3 people should not write BASIC compilers... */