Skip to content

Instantly share code, notes, and snippets.

View sheniff's full-sized avatar

Sergio Almécija sheniff

  • Dropbox Inc
  • San Francisco
View GitHub Profile
@sheniff
sheniff / requiredIf.ts
Last active June 21, 2019 21:12
conditional validator for Angular reactive forms
const requiredIf(condition: (control: AbstractControl) => boolean): (control: FormControl) => ValidationResult {
return (control: FormControl): ValidationResult => {
// Important: control.parent might not be defined, depending on your form structure
return !condition(control.parent) || !!control.value ? null : { [`required_if`]: true };
};
}
@sheniff
sheniff / my .zshrc
Last active December 9, 2016 21:43
# Path to your oh-my-zsh installation.
export ZSH=/Users/sheniff/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Uncomment the following line to use case-sensitive completion.
# I can choose multiple folders with {} and random depth levels with **
for file in client/{app,components}/**/*.js
do
mv "$file" "${file%.js}.ts"
done
@sheniff
sheniff / genymotionwithplay.txt
Created January 29, 2016 23:52 — forked from wbroek/genymotionwithplay.txt
Genymotion with Google Play Services
Download the following ZIPs:
ARM Translation Installer v1.1 (http://www.mirrorcreator.com/files/0ZIO8PME/Genymotion-ARM-Translation_v1.1.zip_links)
Download the correct GApps for your Android version:
Google Apps for Android 6.0 (https://www.androidfilehost.com/?fid=24052804347835438 - benzo-gapps-M-20151011-signed-chroma-r3.zip)
Google Apps for Android 5.1 (https://www.androidfilehost.com/?fid=96042739161891406 - gapps-L-4-21-15.zip)
Google Apps for Android 5.0 (https://www.androidfilehost.com/?fid=95784891001614559 - gapps-lp-20141109-signed.zip)
Google Apps for Android 4.4.4 (https://www.androidfilehost.com/?fid=23501681358544845 - gapps-kk-20140606-signed.zip)
Google Apps for Android 4.3 (https://www.androidfilehost.com/?fid=23060877490000124 - gapps-jb-20130813-signed.zip)
@sheniff
sheniff / optimizedScroll.js
Created September 1, 2015 04:15
Throttled, efficient scroll that only runs once per frame redraw (From MDN documentation https://developer.mozilla.org/en-US/docs/Web/Events/scroll)
;(function() {
var throttle = function(type, name, obj) {
var obj = obj || window;
var running = false;
var func = function() {
if (running) { return; }
running = true;
requestAnimationFrame(function() {
obj.dispatchEvent(new CustomEvent(name));
running = false;
@sheniff
sheniff / emojis
Last active September 11, 2015 19:23
Emojis!
ʘ‿ʘ
Innocent face
ಠ_ಠ
Reddit disapproval face
(╯°□°)╯︵ ┻━┻
Table Flip / Flipping Table
┬─┬ ノ( ゜-゜ノ)
@sheniff
sheniff / gitAliases.zsh
Created June 23, 2015 16:33
Git aliases
alias g='git'
alias gs='git status -s'
alias grb='git rebase'
alias rbm='git rebase master'
alias gra='git rebase --abort'
alias gah='git reset --hard'
alias gr2='git rebase -i -p HEAD~2'
alias gr3='git rebase -i -p HEAD~3'
alias gr4='git rebase -i -p HEAD~4'
@sheniff
sheniff / euler4.js
Created May 3, 2015 06:04
Spoiler Alert: Project Euler 4
var getPalindrome = function(num) {
var str = num.toString().split(''),
len = str.length,
half = len / 2;
for(var i = 0; i < half; i++) {
str[len - 1 - i] = str[i];
}
return parseInt(str.join(''), 10);
@sheniff
sheniff / euler3.js
Created May 3, 2015 04:34
Spoiler Alert: Project Euler 3
var number = 600851475143;
var isPrime = function(num) {
var i = Math.ceil(Math.sqrt(num)),
end = Math.ceil(num / 2);
for(; i < end; i++) {
if (num % i === 0) return false;
}
@sheniff
sheniff / euler2.js
Created May 3, 2015 03:55
Spoiler Alert: Project Euler 2
var sum = 2,
prev = 1,
prev2 = 2,
curr;
while ((curr = prev + prev2) < 4000000) {
prev = prev2;
prev2 = curr;
!(curr % 2) && (sum += curr);