Skip to content

Instantly share code, notes, and snippets.

View adamaiken89's full-sized avatar
😀
happy

Adam Aiken adamaiken89

😀
happy
  • Hong Kong
  • 13:53 (UTC +08:00)
  • LinkedIn in/adamhk
View GitHub Profile
@rjungemann
rjungemann / redis_pubsub.rb
Created May 24, 2010 22:04
A Redis pubsub example for Ruby
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
# http://gist.github.com/348262
# Incomplete evented Redis implementation specifically made for
# the new PubSub features in Redis.
# Modifications by Roger Jungemann
require 'stringio'
@Jach
Jach / sieve.py
Created February 7, 2012 18:43
Incremental Sieve of Eratosthenes
'''
Python implementation of Haskell's
sieve xs = sieve' xs Map.empty
where
sieve' [] table = []
sieve' (x:xs) table =
case Map.lookup x table of
Nothing -> x : sieve' xs (Map.insert (x*x) [x] table)
Just facts -> sieve' xs (foldl reinsert (Map.delete x table) facts)
@le0pard
le0pard / gist:2521687
Created April 28, 2012 20:01
Generate digital signature for image on ruby and compare
require 'RMagick'
require 'yaml'
class ImageDiff
#max = 20
MATRIX = 15
def generate_array(image_path)
result = []
@timcheadle
timcheadle / README.md
Last active January 26, 2023 00:56
Make /robots.txt aware of the Rails environment

Make /robots.txt aware of the Rails environment

You probably don't want Google crawling your development staging app. Here's how to fix that.

$ mv public/robots.txt config/robots.production.txt
$ cp config/robots.production.txt config/robots.development.txt

Now edit config/routes.rb to add a route for /robots.txt, and add the controller code.

@zikes
zikes / index.html
Created December 13, 2012 19:38
Exponential Regression Line Using numbers.js & d3.js
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exponential Regression Line Using numbers.js & d3.js</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="numbers.js"></script>
<style>
body {font: 10px sans-serif;}
@loveky
loveky / Sinatra中request.path_info和request.script_name的区别.md
Last active July 9, 2020 07:35
Sinatra中request.path_info和request.script_name的区别

最近在看Sinatra 1.3.5的源码。在Sinatra::Helpers模块中看到一个名为uri的方法,用来将一个相对路径转换为绝对路径。在该函数的代码中看到分别针对request.script_name和request.path_info进行了处理。但是并不清楚这两个参数的区别,于是做了一些reseach。

二者在RFC3875中有如下定义:

4.1.13. SCRIPT_NAME

The SCRIPT_NAME variable MUST be set to a URI path (not URL-encoded) which could identify the CGI script (rather than the script's output). The syntax is the same as for PATH_INFO (section 4.1.5) >

@ryansobol
ryansobol / gist:5252653
Last active February 23, 2025 06:28
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@kivanio
kivanio / active_admin.css.scss
Last active April 13, 2017 05:13 — forked from amolpujari/article.rb
activeadmin tweks Editable line
input.editable_text_column {
background-color: #FBFF8C;
border: 1px none #FBFF8C;
box-shadow: 0 2px 19px #AAAAAA;
color: black;
display: none;
font-family: serif;
font-size: 1em;
font-style: italic;
height: 30px;
@iwek
iwek / svg-image2.js
Created October 23, 2013 16:26
D3js click function to save SVG as dataurl in IMG tag, load into CANVAS and save as PNG dataurl, and auto download the actual PNG file.
d3.select("#save").on("click", function(){
var html = d3.select("svg")
.attr("version", 1.1)
.attr("xmlns", "http://www.w3.org/2000/svg")
.node().parentNode.innerHTML;
//console.log(html);
var imgsrc = 'data:image/svg+xml;base64,'+ btoa(html);
var img = '<img src="'+imgsrc+'">';
d3.select("#svgdataurl").html(img);
@lfender6445
lfender6445 / gist:9919357
Last active April 11, 2025 19:56
Pry Cheat Sheet

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger