Skip to content

Instantly share code, notes, and snippets.

View MaxPleaner's full-sized avatar

Max Pleaner MaxPleaner

View GitHub Profile
@jdkanani
jdkanani / notepad.html
Last active June 16, 2024 13:44 — forked from jakeonrails/Ruby Notepad Bookmarklet
This bookmarklet gives you a code editor in your browser with a single click.
data:text/html, <style type="text/css">.e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div class="e" id="editor"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("editor");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
<!--
For other language: Instead of `ace/mode/ruby`, Use
Markdown -> `ace/mode/markdown`
Python -> `ace/mode/python`
C/C++ -> `ace/mode/c_cpp`
Javscript -> `ace/mode/javascript`
Java -> `ace/mode/java`
Scala- -> `ace/mode/scala`
@aspyct
aspyct / sort.rb
Last active April 3, 2025 12:24
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
@evanwalsh
evanwalsh / imgur.rb
Created August 21, 2012 00:32
Download an imgur.com gallery with Ruby and Nokogiri
#!/usr/bin/env ruby
# Download imgur.com galleries easily
#
# Requirements:
# gem install nokogiri
#
# Usage:
# ruby imgur.rb [url of gallery] [directory to download into] [namespace for files]
#
@uu59
uu59 / .gitignore
Created August 13, 2012 08:12
socket.io and Sinatra
vendor/
.bundle/
node_modules/
Gemfile.lock
@jboner
jboner / latency.txt
Last active May 17, 2025 16:50
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@dansimco
dansimco / app.rb
Created May 29, 2012 15:09
Concise Sinatra Amazon S3 Upload Example
require "rubygems"
require 'sinatra'
require "aws/s3"
get '/' do
return %Q{
<form action="upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<div>
<input type="file" name="file" value="" id="file">
</div>
@peterc
peterc / equi.rb
Created May 14, 2012 22:23
100% scorer for Ruby on Codility's 'equi' test
# http://codility.com/ for info
def equi(a)
pres, posts = 0, a.reduce(:+)
0.upto(a.length - 1) do |pivot|
pres += (pivot > 0 ? a[pivot-1] : 0)
posts -= a[pivot]
return pivot if pres == posts
end
@jasoares
jasoares / cucumber_init.sh
Created May 4, 2012 17:41
Cucumber init script for non rails applications
#!/bin/bash
# Create the directory structure
mkdir -p features/step_definitions
mkdir -p features/support
# Create a placeholder for the step_definitions folder
touch features/step_definitions/"$(basename `pwd`)_steps.rb"
# Create the environment file
@rlemon
rlemon / master.markdown
Created April 24, 2012 20:42
Stack Overflow Pro-Forma comments
#Stack Overflow Pro-Forma comments
###[A]Answers just to say Thanks!
Please don't add "thanks" as answers. Invest some time in the site and you will gain sufficient privileges to upvote answers you like, which is the community way of saying thank you.
###[Q]Nothing but a URL (and isn't spam)
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
###[A]OP adding a new question as an answer
If you have another question, please ask it by clicking the [Ask Question](http://stackoverflow.com/questions/ask) button.
@peterc
peterc / 16step.coffee
Created February 27, 2012 00:32
Simple 16 step drum machine using CoffeeScript and Node
# Simple 16 step drum machine experiment with Node and CoffeeScript
# by Peter Cooper - @peterc
#
# Inspired by Giles Bowkett's screencast at
# http://gilesbowkett.blogspot.com/2012/02/making-music-with-javascript-is-easy.html
#
# Screencast demo of this code at http://www.youtube.com/watch?v=qWKkEaKL6DQ
#
# Required:
# node, npm and coffee-script installed