Skip to content

Instantly share code, notes, and snippets.

@AfonsoTsukamoto
AfonsoTsukamoto / phpAlertJS.php
Last active December 19, 2015 04:48
Just a _SELF_ reminder for this function that is pretty useful sometimes.
<?php
function php_alert($message){
echo "<script type='text/javascript'>!function(){ alert('". $message . "');}()</script>";
}
//example
...
$result = mysqli_query($someconnection, "SELECT * FROM table");
if(!$result){
@AfonsoTsukamoto
AfonsoTsukamoto / JavascriptOOExample.js
Created November 18, 2013 19:04
Javascript classes. Just as reminder.
// Class Ex.
var JSClass = function(args){
//This is only accessible through a getter
var _arg = args[0];
// This is accesible by json notation: jsclassInstance.jsonAttr
this.jsonAttr = args[1];
var func = function(args){
// This function either is returned or is private to the class
@AfonsoTsukamoto
AfonsoTsukamoto / yield_and_proc_new.rb
Last active August 29, 2015 14:02
[Ruby] Avoid &block in ruby (performance)
##
# This module uses &Proc.new and yield as a way to prevent passing blocks.
# Not tested, as included in another module, changed for gist reasons.
module Semaphore
class << self
attr_accessor :cluster_semaphore
attr_accessor :selector_semaphore
attr_accessor :tagging_semaphore
def init_semaphore
@AfonsoTsukamoto
AfonsoTsukamoto / initializer.rb
Created June 19, 2014 02:24
[Ruby] A intializer
# Found here: http://c2.com/cgi/wiki?PythonRubyInitializer
class Class
def initializer(*args, &b)
define_method(:__init_proc) {b}
params = args.join(", ")
vars = args.collect{|a| "@#{a}"}.join(", ")
class_eval <<-EOS
def initialize(#{params})
#{vars} = #{params}
@AfonsoTsukamoto
AfonsoTsukamoto / remove_nav_back.m
Created August 11, 2014 12:08
[ios] remove nav bar background
//weird voodoo to remove navigation bar background
[navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[navigationController.navigationBar setShadowImage:[UIImage new]];
@AfonsoTsukamoto
AfonsoTsukamoto / nav_title_attrs.m
Created August 11, 2014 12:09
[ios] set attributed text to nav title
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowOffset:CGSizeMake(1, 1)];
[shadow setShadowColor:[UIColor blackColor]];
[shadow setShadowBlurRadius:1];
navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor], NSShadowAttributeName: shadow};
@AfonsoTsukamoto
AfonsoTsukamoto / UIWindow+Touches.m
Last active August 29, 2015 14:05
A category to get a touches began delegate from UIWIndow
static const void *touchesDelegateKey = &touchesDelegateKey;
static void (*Original_touchesBeganMethod)(id, SEL, NSSet *, UIEvent *);
static void SwizzledTouchesBegan(id _self, SEL _cmd, NSSet *touches, UIEvent *event){
if([_self touchesDelegate] != nil){
if([[_self touchesDelegate] respondsToSelector:@selector(windowTouches:withEvent:)]){
[[_self touchesDelegate] windowTouches:touches withEvent:event];
}
}
@AfonsoTsukamoto
AfonsoTsukamoto / unicorn
Last active August 29, 2015 14:06 — forked from shapeshed/unicorn
#!/bin/sh
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/path/to/your/app/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENVIRONMENT=production
@AfonsoTsukamoto
AfonsoTsukamoto / .rubocop.yml
Created October 10, 2014 17:01
The config for rubocop
AllCops:
Exclude:
- 'spec/**/*'
- 'db/**/*'
- 'config/**/*'
- 'bin/**/*'
# Max line length is changed from default 80
Metrics/LineLength:
Max: 100
@AfonsoTsukamoto
AfonsoTsukamoto / pre-commit.rb
Last active August 29, 2015 14:11
A git hook to stop commits with binding pry... for now. Easy to add more expressions.
#!/usr/bin/env ruby
##
# This file must be renamed to pre-commit without extension and
# added to your .git/hooks directory
# After that, run `chmod 755 pre-commit` to make it executable
$user = ENV['USER']