Skip to content

Instantly share code, notes, and snippets.

@chrisbloom7
chrisbloom7 / example_table.html
Created June 11, 2012 18:52
A cucumber/capybara step to test the order of data in a table, either with or without headers
<html>
<body>
<section class="left">
<article id="customers">
<h2>New Customers</h2>
<table class="data">
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
@bogdanRada
bogdanRada / Capybara add Firebug to Selenium test-- Rails+Rspec.rb
Last active July 26, 2016 08:58
Capybara add Firebug to Selenium test-- Rails+Rspec.rb
# for more preferences visit this page
#https://getfirebug.com/wiki/index.php/Firebug_Preferences
require 'selenium/webdriver'
ORIGINAL_FIREBUG_PATH = File.expand_path(File.join(File.dirname(__FILE__),"firebug-2.0.16-fx.xpi"))
ORIGINAL_FIREBUG_URL = "https://getfirebug.com/releases/firebug/1.13/firebug-1.13.0a9.xpi";
@darkhelmet
darkhelmet / actor.rb
Last active December 12, 2015 08:29
Make Your own Celluloid
require 'forwardable'
require 'thread'
require 'monitor'
module LolConcurrency
module Actor
Context = Struct.new(:method, :args, :block)
Async = Struct.new(:instance, :mailbox) do
extend Forwardable
@egonSchiele
egonSchiele / bench.rb
Last active November 11, 2017 10:09
Benchmarking OpenStruct alternatives
require 'benchmark'
require 'ostruct'
require 'rubygems'
require 'deep_struct'
require 'classy_struct'
require 'structure'
require 'deepopenstruct'
require 'recursive-open-struct'
require './fast_struct/lib/fast_struct'
require 'dalli'
require 'memcachier'
module Sprockets
module Cache
# A simple Memcache cache store.
#
# environment.cache = Sprockets::Cache::MemcacheStore.new
#
class MemcacheStore
@willywongi
willywongi / 1-echo.js
Last active July 8, 2025 05:06
Load a Worker from a different domain (CORS + tricks)
/*
You want to use webworkers, but you host all of your js files on a different domain than where
your app lives (es. app.example.com and js.example.com). Given that the static file served from
js.example.com are CORS ready (in that the response header includes Accept-origin: *), I thought
I could load a Worker from other domains. I was almost wrong, but at last I found a solution:
XHRing the worker source and create an inline worker. This is tested only on Firefox (latest).
*/
// This is an example webworker that is on js.example.com. It just echoes messages it receive.
self.onmessage = function(e) {
self.postMessage(e.data);
@scottyab
scottyab / SignatureCheck.java
Last active August 26, 2025 19:14
Simple Android signature check. Please note: This was created in 2013, not actively maintained and may not be compatible with the latest Android versions. It's not particularly difficult for an attacker to decompile an .apk, find this tamper check, replace the APP_SIGNATURE with theirs and rebuild (or use method hooking to return true from `vali…
/*
* Copyright 2013 Scott Alexander-Bown
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@branneman
branneman / better-nodejs-require-paths.md
Last active March 27, 2026 02:24
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@kfox
kfox / sum_exists.rb
Created March 5, 2014 04:07
Find all number pairs in a Ruby array that add up to a given number
#!/usr/bin/env ruby
numbers = [2, 6, 4, 8, 8, 9]
sum = ARGV.empty? ? 10 : ARGV.first.to_i
def sum_exists(numbers, sum)
Array(numbers).combination(2).find_all { |x, y| x + y == sum } || []
end
result = sum_exists(numbers, sum)