Skip to content

Instantly share code, notes, and snippets.

View sideshowcoder's full-sized avatar
💭
🐱

Philipp Fehre sideshowcoder

💭
🐱
View GitHub Profile
@sideshowcoder
sideshowcoder / single.php
Created October 8, 2011 11:04
Wordpress Single PHP theme based on category
<?php
/*
Template Name: Single News
*/
?>
<?php
// Switching if projects or if news
$proj='projects';
$catid=-1;
foreach(get_categories() as $category)
@sideshowcoder
sideshowcoder / nginx_forward_all_https.conf
Created November 3, 2011 16:45
Nginx forward all to https
# Server to forward all HTTP
server {
# replace a.b.c.d with IP
listen a.b.c.d:80;
location / {
if ($host ~* ^(example\.com|www\.example\.com)$ ) {
rewrite ^/(.*)$ https://example.com/$1 permanent;
}
# Nonstandard code 444 closes the connection without sending any headers
return 444;
@sideshowcoder
sideshowcoder / give_me_post_params.php
Created February 14, 2012 13:59
JSON POST Params in PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Give Me Post Params
*
* Check if params are JSON encoded (acording to content-type header) and if so decode and return
* if not simply return the POST array so
*
* @access public
* @return array
*/
@sideshowcoder
sideshowcoder / server_up.js
Created March 28, 2012 08:23
Test if my server is up
$.getScript(base_url + "vapor.js?" + new Date().getTime())
.fail(function(jqxhr, settings, exception) {
fallback();
});
@sideshowcoder
sideshowcoder / argen.rb
Created June 29, 2012 11:24
Use ActiveRecord to generate Random Data on a Table
require "active_record"
require "ffaker"
class Post < ActiveRecord::Base
end
class Generator
SQL_TYPE_TO_DATA_MAPPING = {
:varchar => /^varchar\((\d+)\)/,
@sideshowcoder
sideshowcoder / deploy.rb
Created August 23, 2012 09:28
Stop all thin servers on deploy
before 'foreman:restart', 'foreman:thin_stop'
namespace :foreman do
desc "Stop thin servers"
task :thin_stop, :roles => :app do
rake = fetch(:rake, 'rake')
rails_env = fetch(:rails_env, 'production')
run "cd '#{current_path}' && #{rake} thin:stop RAILS_ENV=#{rails_env}"
end
@sideshowcoder
sideshowcoder / ar_oauth2_example.rb
Created October 2, 2012 16:16
ActiveResource with OAuth2
class ProtectedResource < ActiveResource::Base
# since the gateway uses oauth2 every call needs to be authenticated,
# so the token for is needed
class << self
attr_accessor :token_string
end
# setup the headers for oauth2
def self.headers
{ 'authorization' => "Bearer #{token_string}"}
@sideshowcoder
sideshowcoder / jshint_runner.vim
Created December 18, 2012 08:56
Run JSHint via <leader>h
" Run JSHint if there is a jshint.json present in the project
autocmd FileType javascript map <leader>h :call RunJSHint()<cr>
function! RunJSHint(...)
let to_hint_file = match(expand("%"), '\(.js\)$') != -1
let options_file = "jshint.json"
if filereadable(options_file) && to_hint_file
echo to_hint_file
:w
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
NeverSave < ActiveRecord::Base
before_create :dont_create_me
def dont_create_me
false
end
end
NeverSave.save # => false
NeverSave < ActiveRecord::Base
validate :dont_validate_me
def dont_validate_me
errors.add(:base, "haha I will never validate")
end
end
NeverSave.valid? # => false