Skip to content

Instantly share code, notes, and snippets.

View jasdev's full-sized avatar

Jasdev Singh jasdev

View GitHub Profile
@jasdev
jasdev / .bash_profile
Created December 9, 2013 18:56
.bash_profile
export PATH
cdls() {
if [ -z "$1" ]; then
cd && ls -G
else
cd "$*" && ls -G
fi
}
alias cd=cdls
alias pearp='/Applications/MAMP/bin/php/php5.4.4/bin/pear'
@jasdev
jasdev / color.py
Created December 22, 2013 04:10
quick python to generate the optimum set of RBG values for a set of size COUNT. This uses the technique outlined in this post http://gamedev.stackexchange.com/questions/46463/is-there-an-optimum-set-of-colors-for-10-players
colors = []
for i in range(0, COUNT):
colors.append(colorsys.hsv_to_rgb(fmod(i * 0.618033988749895, 1.0), 0.5, 1.0))
final class SampleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(type: .System)
// ...
button.addTarget(self, action: #selector(SampleViewController.buttonTapped(_:)), forControlEvents: .TouchUpInside)
final class SampleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(type: .System)
// ...
button.addTarget(self, action: #selector(SampleViewController.buttonTapped(_:)), forControlEvents: .TouchUpInside)
@jasdev
jasdev / Runner.java
Created October 31, 2012 03:55
Blum Micali PRG
public class Runner {
/**
* @param args
*/
public static void main(String[] args) {
//Generate the first 100 bits from Blum-Micali PRG with p = 34319, g = 4, and seed x = 1022
long p = 34319;
long g = 4;
@jasdev
jasdev / CharacterSet+StringLiteralConvertible.swift
Created June 30, 2016 01:33
CharacterSet StringLiteralConvertible
extension CharacterSet: StringLiteralConvertible, ExtendedGraphemeClusterLiteralConvertible {
public init(stringLiteral value: String) {
self.init(charactersIn: value)
}
public init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterType) {
self.init(charactersIn: value)
}
public init(unicodeScalarLiteral value: UnicodeScalarType) {
@jasdev
jasdev / FoundationErrorWrapper.swift
Created July 14, 2016 02:05
An attempt at a protocol that can imply the present of specific cases
import Foundation
public protocol FoundationErrorWrapper: ErrorProtocol {
static func wrappingError(_ error: NSError) -> Self
}
enum SomeError: ErrorProtocol, FoundationErrorWrapper {
case a
case wrappingError(NSError)
}
@jasdev
jasdev / Operation.swift
Created February 15, 2016 03:04
NSOperation Subclass with KVO Notifications
class Operation: NSOperation {
override var asynchronous: Bool {
return true
}
private var _executing = false {
willSet {
willChangeValueForKey("isExecuting")
}
@jasdev
jasdev / CustomCell.swift
Last active July 6, 2018 17:29
An approach to safer UITableViewCell and UICollectionViewCell reuse
class CustomCell: UITableViewCell, Reusable {
class var reuseIdentifier: String {
return "customCell"
}
}
class SupaHotCustomCell: CustomCell {
override class var reuseIdentifier: String {
return "supaHotCustomCell"
}
@jasdev
jasdev / paste.txt
Created November 20, 2012 21:11
Keep fighting.
"Sometimes when I find myself comparing myself to others and losing
steam mentally/emotionally, I have to remind myself where I started, the
attitude I had when I began, and how I have already achieved things I never
thought possible and that there is no reason for that to change so long as I
stay committed, balanced, consistent and hungry."