Skip to content

Instantly share code, notes, and snippets.

View 46bit's full-sized avatar
🏳️‍🌈

Miki Mokrysz 46bit

🏳️‍🌈
View GitHub Profile
@46bit
46bit / cookπ
Created April 17, 2011 23:56
A simple Ruby script to calculate using the Chudnovsky algorithm. Seems to only be accurate to 69 d.p. according to http://www.angio.net/pi/bigpi.cgi - likely an issue with the 10005^0.5 precision and perhaps some proper floating point errors?
#!/usr/bin/env ruby
require 'bigdecimal';
class Integer
def factorial
f = 1; for i in 1..self; f *= i; end; f
end
end
@46bit
46bit / ajaxify-html5.js
Created June 22, 2011 01:14 — forked from balupton/README.md
Ajaxify a Website with the HTML5 History API using History.js and ScrollTo
(function(window,undefined){
// Prepare our Variables
var
History = window.History,
$ = window.jQuery,
document = window.document;
// Check to see if History.js is enabled for our Browser
if ( !History.enabled ) {
@46bit
46bit / r_upload.rb
Created September 22, 2011 11:39
Handy scp uploading helper
#!/usr/bin/env ruby
# This is a simple helper for uploading files to a server
# By default it randomises the filename (but preserves the extension)
# Supply -p to maintain original filename
require 'optparse'
require 'digest/md5'
require 'net/scp'
@46bit
46bit / tg.sh
Created September 22, 2011 11:49
TG: my old helper, not very nice
name=$1
#random=$RANDOM + $RANDOM + $RANDOM
md5name=`md5 -s "${name}" | grep -o "[a-z0-9]\{32\}"`
md5name="${md5name}.png"
echo "http://r.46bit.com/${md5name}"
scp "$name" user@server:"/path/to/destination/${md5name}"
#echo "http://host/${md5name}"
@46bit
46bit / plan.rb
Created April 25, 2012 13:13
Plan your day
#!/usr/bin/env ruby
require 'optparse'
options = { }
optparse = OptionParser.new do |opts|
opts.banner = "Plan your day through the cli.\n"
opts.banner += "Usage: plan [-e|--edit]"
options[:edit] = false
@46bit
46bit / tweet.rb
Created May 9, 2012 00:11
CLI Tweet
#!/usr/bin/env ruby
require 'twitter'
Twitter.configure do |config|
# See https://dev.twitter.com/apps
config.consumer_key = ""
config.consumer_secret = ""
config.oauth_token = ""
config.oauth_token_secret = ""
@46bit
46bit / bootloader.js
Created September 3, 2012 05:11
Page-specific Javascript under asset pipeline (Rails)
// Add this to your layout file as the <body> tag:
<body data-page="<%= "#{controller.controller_name}##{controller.method_name}" %>">
// Now save this to /app/assets/javascript/bootloader.js (requires jQuery):
var app = {
actions: [],
action: function (page, callback) {
this.actions[page] = this.actions[page] || [];
this.actions[page].push(callback);
return this;
@46bit
46bit / sss.c
Created September 5, 2012 14:42
Super Simple C
#include <stdio.h>
// Welcome back to C
// Handy to ever explain simple C to a friend
int main (int argc, char const *argv[]) {
printf("%s\n", "Welcome to Count!");
printf("%s %s %s %s%s\n\n", "Printing from", argv[1], "for", argv[2], ".");
int count_from = atoi(argv[1]);
int count_for = atoi(argv[2]);
@46bit
46bit / b_upload.rb
Created November 8, 2012 06:28
My shell file uploader. SCPs files but allows for deleting afterwards, randomising names, etc. Ideal for screenshot uploading.
#!/usr/bin/env ruby
require 'optparse'
require 'digest/md5'
require 'net/scp'
require "fileutils"
options = { }
optparse = OptionParser.new do |opts|
opts.banner = "Usage: b_upload [-p|--preserve|-d|--delete-local] file"
@46bit
46bit / 46bit-sh.zsh-theme
Created November 10, 2012 07:30
My ZSH theme
PROMPT='%{$fg_bold[magenta]%}%n%{$reset_color%}\
%{$fg[magenta]%}@%{$reset_color%}\
%{$fg_bold[magenta]%}%m%{$reset_color%}:\
%{$fg_bold[cyan]%}%c\
%{$fg_bold[red]%} ∴ %{$reset_color%}'