Skip to content

Instantly share code, notes, and snippets.

View asarode's full-sized avatar

Arjun Sarode asarode

View GitHub Profile
function thing({ a = 1, b }) {
console.log(`a: ${a} b: ${b}`)
}
const options = {
b: 2
}
thing(options)
// Original
if (url) {
window.location.href = url;
} else {
window.location.href = noApp;
}
// Better
window.location.href = url || noApp;
'use strict'
function parallel(tasks, max, done) {
let running = 0
let completed = 0
next()
function taskCompleted() {
completed++
console.log(`finished task #${completed}`)
@asarode
asarode / vectorious-origin.js
Last active August 29, 2015 14:25
Some snippets that show how some open source projects first started out
/*
* Initial steps of the mateogianolio/vectorious library
* https://github.com/mateogianolio/gravity/blob/master/js/vector.js
*/
function Vector(x, y) {
this.x = x;
this.y = y;
}
@asarode
asarode / favs.json
Last active August 29, 2015 14:24
A list of my favorite article titles, anime, books, etc.
{"data": [
"Psycho-Pass",
"No Game No Life",
"Steins;Gate",
"Fullmetal Alchemist: Brotherhood",
"Katekyo Hitman Reborn!",
"Ano Hana",
"Commando, Infantry, or Police. Who are you?",
"Superhero.js",
"What every programmer needs to know about game networking",
@asarode
asarode / haunting.js
Created June 9, 2015 22:08
Nightmare patch
// Nightmare patch for weird Chrome bug
Array.prototype.slice.call(document.querySelectorAll('md-input-container label')).forEach(function(label) {
label.style.direction = 'rtl';
setTimeout(function() {
label.style.direction =' ltr';
}, 0)
});
@asarode
asarode / UIColorExtension.swift
Created January 10, 2015 07:36
Swift extension to get luma value of a UIColor
import UIKit
extension UIColor {
func isLightColor() -> Bool {
var red : CGFloat = 0
var green : CGFloat = 0
var blue : CGFloat = 0
self.getRed(&red, green: nil, blue: nil, alpha: nil)
@asarode
asarode / generateRandomColor.swift
Last active May 4, 2024 14:10
Generating random UIColor in Swift
func generateRandomColor() -> UIColor {
let hue : CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0
let saturation : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white
let brightness : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black
return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1)
}