Skip to content

Instantly share code, notes, and snippets.

@hedleysmith
hedleysmith / fetch_vs_jquery_vs_superagent.js
Created August 12, 2016 15:00
HTTP requests three ways - Fetch API vs jQuery.ajax vs Superagent
/*
* Client-side HTTP requests three ways, using ES6 syntax.
* 1. jQuery.ajax()
* 2. Superagent
* 3. Fetch API
* 4. Bonus helper
*/
// 1. jQuery.ajax()
// http://api.jquery.com/jquery.ajax/
@danielpunkass
danielpunkass / fsa.py
Last active July 22, 2018 02:50
A simple lldb module for adding an "fsa" command to inject F-Script anywhere into any process
"""
Automate loading of F-Script Anywhere into any app.
By Daniel Jalkut - @danielpunkass - http://indiestack.com/
To set up:
0. Make sure you have FScript.framework installed in /Library/Frameworks (http://www.fscript.org)
1. Copy this script to ~/.lldb/fsa.py
2. Add the following to your ~/.lldbinit file:
@swannodette
swannodette / om_data.cljs
Last active January 9, 2021 16:09
Om + DataScript
(ns om-data.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[datascript :as d]))
(enable-console-print!)
(def schema {})
(def conn (d/create-conn schema))
@mathieulegrand
mathieulegrand / connect.rs
Last active March 10, 2018 19:57
simple connect to server:443 in Rust
// Rust 0.10-pre (Tue Mar 18, 2014)
// $ rustc -L rust-openssl/build/ -L rust-toml/lib doing.rs
// assuming https://github.com/sfackler/rust-openssl is cloned and compiled,
// and https://github.com/mneumann/rust-tom is cloned and compiled
#[feature(macro_rules)];
#[allow(deprecated_owned_vector)];
extern crate openssl;
extern crate serialize;
@termi
termi / crossBrowser_initKeyboardEvent.js
Last active June 13, 2023 02:01
Cross-browser initKeyboardEvent
void function() {//closure
var global = this
, _initKeyboardEvent_type = (function( e ) {
try {
e.initKeyboardEvent(
"keyup" // in DOMString typeArg
, false // in boolean canBubbleArg
, false // in boolean cancelableArg
, global // in views::AbstractView viewArg
@mattetti
mattetti / gist:3850240
Created October 8, 2012 01:19
Rakefile to generate a mruby mandelbrot example
# Change the path to match the path to your machine.
$mrb_path = File.expand_path("~/src/mruby")
$mrbc = File.join($mrb_path,"/bin/mrbc")
task :default do
# dumps the Ruby file to disk
File.open("mandelbrot.rb", "w"){|f| f << mandelbrot_ruby_code }
# creates the .c file containing mandelbrot char array for the bytecode
`#{$mrbc} -Bmandelbrot_bytecode ./mandelbrot.rb`
example_file = wrapper_code(File.read("./mandelbrot.c"))
@edwardsmit
edwardsmit / gist:1768015
Created February 8, 2012 10:33
Using Veewee 0.3.0.Alpha9 for creating a vagrant basebox and using it in Vagrant
# Vagrant is installed
# VirtualBox is installed
# pwd: ~/Vagrant
git clone https://github.com/jedi4ever/veewee.git
cd veewee/
bundle install
git pull
bundle update
bundle exec veewee vbox templates
@mager
mager / area_code.rb
Created July 1, 2011 05:36
Get area code from IP address using SimpleGeo Places & Ruby
SimpleGeo::Client.set_credentials(ENV['SIMPLEGEO_KEY'],ENV['SIMPLEGEO_SECRET'])
resp = SimpleGeo::Client.geocode_from_ip()
options = {:num=>1}
place = SimpleGeo::Client.get_places(resp[:query][:latitude], resp[:query][:longitude], options)
phone = place[:features][0][:properties][:phone]
@area_code = phone[3..-10] # Phone number format: "+1 XXX XXX-XXXX"
@vishnuvyas
vishnuvyas / levenshtein.clj
Created May 6, 2011 05:29
A purely functional implementation of levenshtein distance in clojure
(ns levenshtein
^{:doc "A purely functional implementation of the levenshtien distance in clojure"})
(defn- compute-next-row
"computes the next row using the prev-row current-element and the other seq"
[prev-row current-element other-seq pred]
(reduce
(fn [row [diagonal above other-element]]
(let [update-val
(if (pred other-element current-element)
@mattetti
mattetti / fsevents.rb
Created March 18, 2011 07:19
FSEvents API implementation in MacRuby
if RUBY_ENGINE == 'macruby'
framework 'CoreServices'
WATCHED_EXTS = "rb,builder,erb,nokogiri"
PASSENGER_RESTART_FILE = File.expand_path(File.join(File.dirname(__FILE__), "..", "tmp", "restart.txt"))
DELAY = 3
def modified_files(path)
Dir.glob("#{File.expand_path(path)}/*.{#{WATCHED_EXTS}}").map do |filename|
begin