Skip to content

Instantly share code, notes, and snippets.

View sycue's full-sized avatar

sycue

View GitHub Profile
@madhums
madhums / express.mobile.js
Last active December 18, 2015 11:59
render mobile layouts using express.js
// Render mobile views
// if the request is coming from mobile and if you have a view
// with users.mobile.jade, then that view will be rendered
app.use(function (req, res, next) {
res._render = res.render
res.render = function (template, locals, cb) {
var ua = req.header('user-agent')
var fs = require('fs')
#!/usr/bin/env ruby
#------------------------------------------------------------------------------
# Aggregate Print useful information from /proc/[pid]/smaps
#
# pss - Roughly the amount of memory that is "really" being used by the pid
# swap - Amount of swap this process is currently using
#
# Reference:
# http://www.mjmwired.net/kernel/Documentation/filesystems/proc.txt#361
@shanselman
shanselman / gist:5422230
Last active September 18, 2024 06:47
Evil Blog Comment Spammer just exposed his template through some error and the whole thing showed up in my comments.
{
{I have|I've} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours. {It's|It
is} pretty worth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web owners} and bloggers made good content as
you did, the {internet|net|web} will be {much more|a lot more}
useful than ever before.|
I {couldn't|could not} {resist|refrain from} commenting. {Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I'll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch}
your {rss|rss feed} as I {can not|can't} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service. Do {you have|you've} any?
{Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I {may just|may|could} subscribe.
Thanks.|
@jakeonrails
jakeonrails / Ruby Notepad Bookmarklet
Created January 29, 2013 18:08
This bookmarklet gives you a code editor in your browser with a single click.
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
@woodywang
woodywang / parser-bool-mongodb.py
Created December 18, 2012 03:11
A parser which convert SQL-like boolean expression into MongoDB condition expression.
import re
import json
OP_STACK = list()
ELEM_STACK = list()
COMP_STACK = list()
OP_MONGO_MAP = dict({
'AND': '$and',
'OR': '$or',
Namespace = ( ->
merge = (target, source) ->
for key, val of source
target[key] = val
target
_assertValidFQN = (fqn) ->
unless ///^[a-z0-9_.]+///.test fqn then throw 'invalid namespace'
class Procedure
@nono
nono / blowfish.rb
Created June 26, 2012 10:57
How to encrypt and decrypt Blowfish in Ruby 1.9 with https://github.com/drench/blowfish.js
#!/usr/bin/env ruby
require "openssl"
class BF < Struct.new(:key, :pad_with_spaces)
def encrypt(str)
cipher = OpenSSL::Cipher.new('bf-ecb').encrypt
if pad_with_spaces
str += " " until str.bytesize % 8 == 0
cipher.padding = 0
@phinze
phinze / disinterested_cat.rb
Created May 3, 2012 05:14
simple dynamic dispatch example
class DisinterestedCat
def speak
puts "..."
end
def play
puts "...<look away>"
end
end
@seeflanigan
seeflanigan / appusers.rb
Created May 3, 2012 04:56 — forked from kartikrustagi/appusers.rb
Auth using Sinatra-Warden
require 'openssl'
class AppUser < Sequel::Model(:AppUsers)
AppUser.unrestrict_primary_key
def self.authenticate(username, password)
#TODO: Store salt in config
puts "In Auth"
user = self.first(:username => username)
@vikks
vikks / app.coffee
Created May 3, 2012 04:42 — forked from mikeobrien/app.coffee
Lazy loading backbone collection + infinite scrolling
class LazyCollection extends Backbone.Collection
indexQuerystring: 'index'
index: 1
lastLength: 0
fetch: (options) ->
options or= {}
if options.reset
@index = 1
@lastLength = 0
else