Skip to content

Instantly share code, notes, and snippets.

View th3hunt's full-sized avatar
🎯
Focusing

Stratos Pavlakis th3hunt

🎯
Focusing
  • Blueground
  • Athens
View GitHub Profile
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
upstream app {
server unix:/srv/app/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.app.com;
rewrite ^/(.*) http://app.com/$1 permanent;
}
server {
# Here's a contrived example of a LEFT JOIN using ARel. This is an example of
# the mechanics, not a real-world use case.
# == DEFINITIONS
# - A Taxi is a car for hire. A taxi has_many :passengers.
# - A Passenger records one person riding in one taxi one time. It belongs_to :taxi.
class Taxi < ActiveRecord::Base
# This scope LEFT JOINs the Passenger table. You might use this if you wanted
# to select taxis by a set of taxi and passenger IDs (as with the
@th3hunt
th3hunt / mobile_application_controller.rb
Created November 26, 2013 15:32
From scottwb, A Better Way to Add Mobile Pages to a Rails Site
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def check_for_mobile
session[:mobile_override] = params[:mobile] if params[:mobile]
prepare_for_mobile if mobile_device?
end
def prepare_for_mobile
prepend_view_path Rails.root + 'app' + 'views_mobile'
end
#!/bin/sh
#
# Use ipfw to throttle bandwidth.
# usage:
# ./throttle.sh # Throttle at default (60KB/s)
# ./throttle.sh 5 # Throttle at custom speed (5KB/s)
# ./throttle.sh off # Turn throttling off
# flush rules
ipfw del pipe 1
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.1098039299249649</real>
<key>Green Component</key>
<real>0.1098039299249649</real>
@th3hunt
th3hunt / .jshintrc
Last active January 3, 2016 03:09
JSHint configuration
// JSHint Configuration File
{
"maxerr" : 50, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : true, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
@th3hunt
th3hunt / js-guidelines-sample.js
Last active January 3, 2016 03:09
Javascript Style - sample code
/* jshint node: true */
'use strict';
var BaseSrv = require('./BaseService')
, Q = require('q')
, async = require('async')
, crypto = require('crypto')
, fs = require('fs')
, ejs = require('ejs');
@th3hunt
th3hunt / .jslintrc
Last active January 7, 2018 02:40 — forked from irae/.jslintrc
JSLint configuration
{
/*** Globals ***/
// To ignore any custom global variables, enable the `predef` option and list
// your variables within it.
"predef": [
"window",
"document",
"jQuery",
"Backbone",
"Marionette",
@th3hunt
th3hunt / api_controller_boilerplate.rb
Created January 24, 2014 12:56
Rails API Controller Boilerplate
require 'json_responder'
class Api::V1::ApiController < ActionController::Base
respond_to :json
before_filter :authenticate_user
self.responder = JsonResponder
rescue_from ActiveRecord::RecordNotFound, with: :not_found
rescue_from ActiveModel::MassAssignmentSecurity::Error, with: :bad_request
rescue_from AccessForbidden, with: :access_forbidden
rescue_from InvalidTransition, with: :invalid_transition