This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func base64Encoded() -> Data? { | |
return self.data(using: .utf8) | |
} | |
func base64Decoded() -> Data? { | |
if self.range(of: ":")?.lowerBound != nil { | |
return self.data(using: .utf8) | |
} | |
let base64String = self.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ActiveSupport has it. | |
class Array | |
def sum | |
if self.size == 0 | |
return 0 | |
else | |
self.inject(:+) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Interactive PoPToP install script on a OpenVZ VPS | |
# Tested on Debian 5, 6, and Ubuntu 11.04 | |
# 2011 v1.1 | |
# Author: Commander Waffles | |
# http://www.putdispenserhere.com/pptp-debian-ubuntu-openvz-setup-script/ | |
echo "######################################################" | |
echo "Interactive PoPToP Install Script for OpenVZ VPS" | |
echo "by Commander Waffles http://www.putdispenserhere.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it(@"should instantiate the view controller", ^{ | |
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; | |
ViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"ViewController"]; | |
[[vc shouldNot] beNil] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import * | |
env.hosts = ["app1", "app2"] | |
env.use_ssh_config = True | |
def host_type(): | |
run('df -h') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal(object): | |
def __init__(self): | |
self.name = "Animal" | |
def eat(self, food = "nothing"): | |
print self.name + " eats " + food | |
# ================================================== | |
import animal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prev_time = Time.now | |
100000.times do | |
request = WifiRequest.where(client_mac_addr: "B0:8E:1A:50:03:ED").last | |
next if request.request_at == prev_time | |
puts request.slice(:client_mac_addr, :power, :request_at) | |
prev_time = request.request_at | |
sleep 5 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 1 ============================================= | |
class ProjectManagerChecker | |
def self.matches?(request) | |
request.env['warden'].user.role == 'project_manager' | |
end | |
end | |
# routes.rb | |
get '/' => 'project_managers#index', :constraints => ProjectManagerChecker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def is_katakana? | |
(self =~ /^[゠-ヿ -〿]+$/) == 0 | |
end | |
def is_half_katakana? | |
(self =~ /^[⦅-゚ -〿]+$/) == 0 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function longRunJob() { | |
var deferred = $q.defer(); | |
setTimeout(function(){ | |
deferred.notify('About to greet ' + name + '.'); | |
deferred.resolve('Hello, ' + name + '!'); | |
deferred.reject('Greeting ' + name + ' is not allowed.'); | |
}, 10000) | |
return deferred.promise; | |
} |
NewerOlder