Skip to content

Instantly share code, notes, and snippets.

View christopherdebeer's full-sized avatar

Christopher de Beer christopherdebeer

View GitHub Profile
@christopherdebeer
christopherdebeer / snippet.js
Created September 7, 2011 09:22
Node.js Express - Mobile detection
app.get('/', function(req, res){
var ua = req.header('user-agent');
if(/mobile/i.test(ua)) {
res.render('mobile.html');
} else {
res.render('desktop.html');
}
});
@christopherdebeer
christopherdebeer / HNtwit.js
Created October 6, 2011 14:12
Hackernews scan for users that mention a twitter username in their bio
(function(){
$("a[href^='user?id']").each(function(i,e){
var username = $(e).text();
$.get("/user?id=" + username, function(data){
//console.log(data);
var twitternames = data.match(/(?:twitter\.com\/([a-zAZ0-9]+))|(?:[^a-z,^A-Z,^0-9]@([a-z,A-z,-9]+))/gi);
if (twitternames) {
$.each(twitternames,function(i,e) {
twitternames[i] = twitternames[i].replace(/[^a-zA-Z0-9]+@([a-zA-Z0-9]+)/gi,"@$1");
twitternames[i] = twitternames[i].replace(/twitter\.com\//gi,"@");
var testJSON = {
div: {
attributes: {
class: ["wrapper"],
id: "wrapper",
},
innerHTML: {
h1: {
attributes: {
@christopherdebeer
christopherdebeer / bio.json
Last active September 30, 2015 08:27
Christopher de Beer Bio
{
"Christopher de Beer": {
"Location": "Edinburgh, UK",
"Job" : {
"Company": "Amazon.com",
"Roles": [
"Web Develeopment Engineer"
],
},
"Social": {
@christopherdebeer
christopherdebeer / scrape_tweets.rb
Created March 25, 2012 14:50 — forked from stefl/scrape_tweets.rb
Download all tweets from the twitter search API for a given search term (limited to their maximum of 1500)
#! /usr/bin/env ruby
search_term = ARGV[0]
if search_term
time = Time.now
directory_path = File.dirname(__FILE__) + "/tweets/" + search_term + "_" + time.to_i.to_s
Dir.mkdir_p(directory_path)
directory = Dir.new(directory_path)
(1..15).each do |i|
`curl "http://search.twitter.com/search.json?q=#{search_term}&rpp=100&page=#{i}&include_entities=true&result_type=mixed" > #{directory.path}/#{i}.json`
end
@christopherdebeer
christopherdebeer / gist:2331687
Created April 7, 2012 19:56 — forked from mikeal/gist:2331127
safe .toJSON()
function getSafe (self, uuid) {
if (typeof self === 'object' || typeof self === 'function') var safe = {}
if (Array.isArray(self)) var safe = []
var recurse = []
Object.defineProperty(self, uuid, {})
var attrs = Object.keys(self).filter(function (i) {
if (i === uuid) return false
@christopherdebeer
christopherdebeer / layout2.jade
Created July 9, 2012 15:23 — forked from kmiyashiro/layout2.jade
HTML5 Boilerplate Conditional comments in Jade
!!! 5
//if lt IE 7
html(class="no-js ie6 oldie", lang="en")
//if IE 7
html(class="no-js ie7 oldie", lang="en")
//if IE 8
html(class="no-js ie8 oldie", lang="en")
// [if gt IE 8] <!
html(class="no-js", lang="en")
// <![endif]
@christopherdebeer
christopherdebeer / index.js
Created July 17, 2012 15:59 — forked from aemkei/index.js
Obfuscate JS
// RUN THIS IN JAVASCRIPT
([]+{}+[])[!!{}+![]]+([]+
{}+[])[!!{}+!![]]+(!{}+[]
)[!{}+![]]+([][{}]+[])[!{
}+![]]+(!{}+[])[![]+!!{}+
!!{}+!![]]+({}+{})[(!!{}+
!![])*(!!{}+!![])+!!{}]+(
{}-{}+[])[!!{}+![]]+([]+!
!{})[!{}+![]]+([]+!!{})[!
@christopherdebeer
christopherdebeer / error.md
Created August 18, 2012 16:08
Cordova 2.0.0 Error OSX

#Cordova 2.0.0 Error OSX

Calling: sudo ./create ~/cordovatest com.christopherdebeer.test01 testapp *

  • When in the /bin/ folder of Cordova-2.0.0 dmg unpacked from phonegap-phonegap-2.0.0-0-g2dbbdab.zip

Returns the following error:

/Volumes/Cordova-2.0.0/bin/replaces: line 28: tmpFile: Read-only file system mv: tmpFile: No such file or directory
@christopherdebeer
christopherdebeer / gist:3394765
Created August 19, 2012 13:23
text selection bookmarklet code unminified from marksaved.com
//javascript:
(function () {
var enc = encodeURIComponent;
var s = window.getSelection();
if (location.href == "http://marksaved.com/welcome") {
alert("Drag this button to the toolbar to start highlighting")
} else if (s && encodeURIComponent(s).length > 1300) {
alert("Sorry, you can only highlight up to 1K characters")
} else {
var d = document;