Skip to content

Instantly share code, notes, and snippets.

@irokhes
irokhes / fake-date-sinon-node-js
Created June 4, 2016 13:22
Fake a date in node.js for testing with sinon
clock = sinon.useFakeTimers(new Date(2016,11,1).getTime());
new Date(); //=> return the fake Date 'Sat Nov 01 2016 00:00:00'
clock.restore();
new Date(); //=> will return the real time again (now)
@irokhes
irokhes / web-api-self-hosted-Program.cs
Created June 15, 2016 14:28
Web api service self hosted using OWIN
using Microsoft.Owin.Hosting;
using System;
using System.Net.Http;
//Install-Package Microsoft.AspNet.WebApi.OwinSelfHost
namespace WebApi.SelfHosting.POC
{
static class Program
{
static void Main()
{
app.config(function($routeProvider){
$routeProvider
.when('/secretpage' ,{
templateUrl: "templates/secretpage.html",
resolve:{
"check":function(authService,$location){ //function to be resolved, accessFac and $location Injected
if(authService.isAuthenticated()){ //This happens before the page loads
//it's ok to see the content
}else{
$location.path('/'); //redirect user to home if it does not have permission.
@irokhes
irokhes / miliseconds-2-human-readable-time
Created January 23, 2017 22:47
Javascript => convert time in milliseconds to hours, minutes ands seconds
function msToTime(duration) {
var milliseconds = parseInt((duration%1000)/100)
, seconds = parseInt((duration/1000)%60)
, minutes = parseInt((duration/(1000*60))%60)
, hours = parseInt((duration/(1000*60*60))%24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
@irokhes
irokhes / index.js
Last active October 16, 2018 21:48
Flat2Tree
var input = [
{
"start": 1526915703627,
"tier": "2467-359-7565-2166-7060"
},
{
"start": 1526915703639,
"tier": "2467-359-7565-2166-4115-9714"
},
{
@irokhes
irokhes / assert-rejection
Created November 28, 2018 14:51
Function to assert against promise rejection
//Credit to:
//https://www.nearform.com/blog/avoiding-common-hurdles-in-unit-testing/
const expectRejection = async (p, message) => {
try {
await p
} catch (error) {
if (error.message === message) return
throw new Error('Expected error "${message}" but found "${error.message}"')
}

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@irokhes
irokhes / Readme.md
Last active October 5, 2022 11:47 — forked from cunneen/Readme.md
Install Open GApps In Android Emulator

Introduction

This works to install Open GApps into the Android Emulator, working around the issue where the system partition is too small.

With it, I can get Google Play installing into the emulator. Tested on KitKat (API 19), Lollipop (API 21) and Oreo (API 27).

It's tested on MacOS.

Instructions

Restart deployment

kubectl rollout restart deploy/admission-control

Instalación

$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version
@irokhes
irokhes / restart_mac_audio_driver_command
Created March 10, 2020 11:44
Restart Mac audio driver
sudo kill -9 `ps ax|grep 'coreaudio[a-z]' | awk '{print $1}'`