Skip to content

Instantly share code, notes, and snippets.

View bitops's full-sized avatar

Sebastian Wittenkamp bitops

View GitHub Profile
@ghoseb
ghoseb / factorial.py
Created November 14, 2008 18:58
The evolution of a Python Programmer
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@jamis
jamis / Easy Marshmallow Recipe
Created December 10, 2009 22:38
Easy Gourmet Marshmallows
EASY MARSHMALLOWS
-----------------
Marshmallows are perhaps one of the simplest confections you can make. They only
require a handful of ingredients, a batch can be thrown together in 10-15 minutes
(plus *cough* 3 hours for them to set), and you can flavor them however you like.
(You haven't LIVED until you've had coconut marshmallows!)
Hardware needed:
@jamis
jamis / recursive-backtracker2.rb
Created December 27, 2010 04:36
An implementation of the recursive backtracking algorithm that *gasp* actually uses recursion.
# --------------------------------------------------------------------
# Recursive backtracking algorithm for maze generation. Requires that
# the entire maze be stored in memory, but is quite fast, easy to
# learn and implement, and (with a few tweaks) gives fairly good mazes.
# Can also be customized in a variety of ways.
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# 1. Allow the maze to be customized via command-line parameters
# --------------------------------------------------------------------
@jamis
jamis / lap_timer.rb
Created June 6, 2011 22:02
A simple helper for timing sequences of code.
# Easy to use:
#
# timer = LapTimer.new
# # some task that might take awhile
# timer.mark :step2
# # another task that needs timing
# timer.mark :step3
# # and another task to time
# timer.report
#
@danielhawkes
danielhawkes / MediaPlayerStateWrapper.java
Created June 16, 2011 15:58
A drop-in replacement for a MediaPlayer instance, that provides an accessor for the current state.
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import android.media.AudioManager;
import android.media.MediaPlayer;
@jamis
jamis / demo.rb
Created August 3, 2011 21:56
Repairing a unicode string that contains invalid characters
# encoding: utf-8
s = "Blah \xe9 blah 헌글"
puts "BEFORE"
puts "encoding: #{s.encoding}"
puts "valid : #{s.valid_encoding?}"
puts "text : #{s}"
s = s.
@mbbx6spp
mbbx6spp / t4r-client-examples.rb
Created August 28, 2011 02:37
Examples of using Twitter4R (Ruby gem library to access the Twitter.com REST and Search APIs).
# Below are examples of how to initialize and use a Twitter::Client object for each Twitter user
# Can initialize by passing in Hash of oauth_access information for the authenticated user driving calls
# through Twitter4R
twitter = Twitter::Client.new(:oauth_access => {
:key => ACCESS_KEY, :secret => ACCESS_SECRET })
# Can also initialize by loading in file configuration file and specifying YAML key name to use for user:
twitter = Twitter::Client.from_config("file/name/to/config.yml", "key") # YAML file will look like twitter.yml
##### STATUS APIs ######
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 3, 2024 19:09
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@swannodette
swannodette / gist:3217582
Created July 31, 2012 14:52
sudoku_compact.clj
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
@aspyct
aspyct / sort.rb
Last active October 29, 2023 03:08
Ruby implementation of quicksort, mergesort and binary search
# Sample implementation of quicksort and mergesort in ruby
# Both algorithm sort in O(n * lg(n)) time
# Quicksort works inplace, where mergesort works in a new array
def quicksort(array, from=0, to=nil)
if to == nil
# Sort the whole array, by default
to = array.count - 1
end