Skip to content

Instantly share code, notes, and snippets.

View octplane's full-sized avatar
👨‍💻
I came here for the javascript jokes and was disappointed

Pierre Baillet octplane

👨‍💻
I came here for the javascript jokes and was disappointed
View GitHub Profile
@octplane
octplane / meteobot.rb
Created July 23, 2013 11:49
Les sources de FotonautsBot
require 'mechanize'
require 'chatterbot'
require 'htmlentities'
BASE_URL = "http://meteo.orange.fr/Php/getPrevPluies.php"
ARG = "code=0751080"
def get_weather
agent = Mechanize.new
@octplane
octplane / fb_to_nginx.sh
Last active December 18, 2015 19:09
Expand list of ipv4 hosts for all the source of the facebook crawler into a set of nginx Allow directives
whois -h whois.radb.net -- '-i origin AS32934' | grep ^route: | sed -e "s/route: /allow/;s/$/;/"
# https://dev.twitter.com/discussions/6545
whois -h whois.radb.net -- '-i origin AS13414' | grep ^route | sed -e "s/route: /allow/;s/$/;/"
@octplane
octplane / newrelic.rb
Last active December 17, 2015 17:09
Initializer for rails if you use newrelic outside Heroku or without Mongrel. Will speed up all instrumented request by about 100%
module NewRelic
module Agent
module Instrumentation
# == NewRelic instrumentation for controller actions and tasks
#
# This instrumentation is applied to the action controller to collect
# metrics for every web request.
#
# It can also be used to capture performance information for
# background tasks and other non-web transactions, including
@octplane
octplane / plop.rb
Created March 12, 2013 09:55
How to talk to graphite.
send_graphite("munin5.mysql.slow_count %.5f %d" % [@slow_count.to_f/@interval, Time.now.to_i])
def send_graphite(message)
hostname = 'graphite'
port = 2003
begin
s = TCPSocket.open(hostname, port)
s.puts(message)
s.close
@octplane
octplane / v8_memory_stress.rb
Created February 22, 2013 10:33
Stress Test V8 to exhibit memory usage. Uncomment line 5 to demonstrate that SetFlagsFromString has actual impact on the V8 runtime.
require 'rubygems'
require 'handlebars'
require 'v8'
# V8::C::V8.SetFlagsFromString("--max-old-space-size=200")
@heap_stats_methods = [:total_heap_size, :total_heap_size_executable, :used_heap_size, :heap_size_limit]
@st = V8::C::HeapStatistics.new
def dump_stats
@octplane
octplane / build.sbt
Created February 7, 2013 12:28
Ruby syntax validity checker (JRuby) Javascript syntax validity checker. (Rhino)
libraryDependencies += "org.jruby" % "jruby" % "1.7.2"
libraryDependencies += "org.mozilla" % "rhino" % "1.7R4"
ADJECTIVE POS FREQ NEG FREQ TomDS
tout 0.64 0.36 0.2
petit 0.59 0.41 0.0
grand 0.75 0.25 0.2
seul 0.73 0.27 -0.2
autre 0.48 0.52 -0.1
même 0.47 0.53 0.0
bon 0.56 0.44 0.7
premier 0.51 0.49 0.5
beau 0.77 0.23 0.9
@octplane
octplane / epir.arduino
Created July 8, 2012 21:22
ePIR arduino sample code
#include <SoftwareSerial.h>
// This is the input and output of the ePIR
#define rxPin 3
#define txPin 2
// we will switch on and off the onboard led.
#define onBoardLed 13
// set up a new serial port
@octplane
octplane / backtrace
Created July 5, 2012 17:07
Backtrace of stuck resque worker
[Thread debugging using libthread_db enabled]
[New Thread 0x7f8672507700 (LWP 3582)]
0x00000000004ba000 in find_entry (table=0xaa60c8, key=86239440, value=0x7fffa63b4a78) at st.c:451
in st.c
#0 0x00000000004ba000 in find_entry (table=0xaa60c8, key=86239440, value=0x7fffa63b4a78) at st.c:451
#1 st_lookup (table=0xaa60c8, key=86239440, value=0x7fffa63b4a78) at st.c:505
#2 0x00000000004f53dd in rb_mark_generic_ivar (obj=86239440) at variable.c:910
#3 0x000000000041ecc2 in gc_mark_children (objspace=0x9ac990, ptr=86239440, lev=1) at gc.c:1868
#4 0x000000000041f9fc in mark_locations_array (start=0xaef68d0, end=<value optimized out>) at gc.c:1603
#5 gc_mark_locations (start=0xaef68d0, end=<value optimized out>) at gc.c:1616
@octplane
octplane / .gdbinit
Created July 3, 2012 13:29
Dump Stacktrace in ruby 1.9.3 in gdb
define ruby_stack_trace
set $VM_FRAME_MAGIC_METHOD = 0x11
set $VM_FRAME_MAGIC_BLOCK = 0x21
set $VM_FRAME_MAGIC_CLASS = 0x31
set $VM_FRAME_MAGIC_TOP = 0x41
set $VM_FRAME_MAGIC_FINISH = 0x51
set $VM_FRAME_MAGIC_CFUNC = 0x61
set $VM_FRAME_MAGIC_PROC = 0x71
set $VM_FRAME_MAGIC_IFUNC = 0x81
set $VM_FRAME_MAGIC_EVAL = 0x91