Skip to content

Instantly share code, notes, and snippets.

View Veejay's full-sized avatar

Bertrand Chardon Veejay

View GitHub Profile
@Veejay
Veejay / workaround.js
Last active December 12, 2015 02:09
Workaround for Flickr images "click-to-display"
// Straight DOM / Javascript
// Images are blocked through a data attribute client-side
var targetImages = document.querySelectorAll('img[data-blocked-src]')
// Go through all the blocked images and replace the node with an img element
// using the proper link as its source
for(var i = 0, l = targetImages.length; i < l; i++) {
visibleImage = document.createElement('img');
visibleImage.src = targetImages[i].getAttribute('data-blocked-src');
targetImages[i].parentNode.replaceChild(visibleImage, targetImages[i]);
@Veejay
Veejay / channels_select.go
Created January 18, 2013 06:09
Example of channel communication with a simple select statement. Taken from Rob Pike's slides about concurrency in Go.
package main
import (
"fmt"
"time"
)
func boring(msg string) <-chan string { // Returns receive-only channel of strings.
c := make(chan string)
go func() { // We launch the goroutine from inside the function.
package main
import (
"fmt"
"net/http"
"strings"
"log"
"io/ioutil"
"path/filepath"
"os"
)
@Veejay
Veejay / firstprog.go
Created January 11, 2013 23:43
First Go program. Iterates over a map and reads the content of a given directory.
package main
import "fmt"
import "os"
func main() {
m := make(map[string]int)
m["foo"] = 1
m["blah"] = 2
@Veejay
Veejay / detect.js
Created November 13, 2012 22:03
detect
_.detect(collection, function(item) {
// conditions here
},
{
one: function(item) {
// function to execute when one item is found
},
none:function(){
// function to execute when no item is found
}
@Veejay
Veejay / bug
Created November 12, 2012 19:23
Ruby Interpreter Bug
staffplan/ $ bundle exec rails console [11:21:10 (v2!!!) ]
/Users/bertrand/.rbenv/versions/1.9.3-p286/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/http/mime_type.rb:102: warning: already initialized constant MOBILE
Loading development environment (Rails 3.2.8)
irb(main):001:0> exit
/Users/bertrand/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/irb.rb:83: [BUG] Segmentation fault
ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-darwin12.2.0]
-- Control frame information -----------------------------------------------
c:0032 p:---- s:0118 b:0118 l:000117 d:000117 CFUNC :throw
c:0031 p:0015 s:0113 b:0113 l:000112 d:000112 METHOD /Users/bertrand/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/irb.rb:83
@Veejay
Veejay / permissions.rb
Created October 31, 2012 01:05
Decorator method
def permissions_information_for_company(company)
init_haml_helpers
m = user.memberships.where(company_id: company.id).first
capture_haml do
haml_tag :div, {:class => "permissions_info"} do
haml_tag :h2 do
haml_concat "Permissions"
end
if m.permissions.present?
haml_concat "#{user.full_name} has the following permissions for company #{company.name}:"
@Veejay
Veejay / date.rb
Created October 30, 2012 18:36
Date handling
irb(main):009:0> d = Date.new(2012, 12, 31)
=> #<Date: 2012-12-31 ((2456293j,0s,0n),+0s,2299161j)>
irb(main):010:0> d.cweek
=> 1
irb(main):011:0> d.year
=> 2012
@Veejay
Veejay / date.rb
Created October 30, 2012 18:06
Funky Date handling
irb(main):022:0> Date.parse("2012/12/31").cweek
=> 1
irb(main):023:0> Date.parse("2012/12/31").year
=> 2012
@Veejay
Veejay / test.c
Created September 21, 2012 22:49
static linked_list**
find_key(linked_list *list, char *key)
{
linked_list *current = list;
while(!(current && (strcmp(current->kv.key, key)))){
current = current->next;
}
return &(current);
}