Skip to content

Instantly share code, notes, and snippets.

View alonronin's full-sized avatar
:octocat:
Me. Write. Code.

Alon Valadji alonronin

:octocat:
Me. Write. Code.
View GitHub Profile
@alonronin
alonronin / LICENSE.txt
Created July 14, 2012 01:47 — forked from LeverOne/LICENSE.txt
generate random v4 UUIDs (107 bytes)
DO WTF YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Alexey Silin <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WTF YOU WANT TO PUBLIC LICENSE
@alonronin
alonronin / gist:5545119
Created May 9, 2013 02:19
node.js mongoose random documents
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var schema = new mongoose.Schema({
name: String,
email: String,
random: {type: [Number], default: function(){ return [Math.random(), Math.random()]}, index: '2d'}
});
@alonronin
alonronin / helpers.js
Created July 4, 2013 16:44
Mongoose helper for paginate a query
var mongoose = require('mongoose');
mongoose.Model.paginate = function(query, page, records, callback){
page || (page = 1);
page = page.toNumber().abs();
var from = (page * records) - records;
query.skip(from).limit(records).exec(function(err, results){
if(err) return callback(err);
@alonronin
alonronin / dust_compiler.js
Created November 19, 2014 15:52
Compile dust folder strucure
var dust = require('dustjs-linkedin');
var diveSync = require("diveSync");
var path = require('path');
var fs = require('fs');
var dir = path.join(__dirname, 'public', 'templates');
var output = path.join(__dirname, 'public', 'js', 'templates.js');
var writer = fs.createWriteStream(output);
@alonronin
alonronin / angular.binding.html
Last active August 29, 2015 14:11
Angular Two Way data-binding with Casting and Filters (http://jsbin.com/tepoleceli/8/edit?html,js,output)
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="angular.binding.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app="myApp">
@alonronin
alonronin / _reduce.js
Created December 17, 2014 16:36
using the reduce function to accumalate an array of obejcts
var _ = require('lodash');
var arr = [
{
"securityGroupId": 9721,
"isProtected": true,
"securityGroupName": "efvsevcsev",
"vpcId": "vpc-6b2aca0e",
"regionId": "us_west_1",
"cloudAccountId": "dff0b5fd-6161-4eef-aec9-8a9853d9860e",
@alonronin
alonronin / directive.public.api.html
Created May 31, 2015 14:31
Exposing directive public api to parent controller
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<meta charset="utf-8">
<title>My App</title>
</head>
<body ng-app="MyApp">
<div ng-controller="AppCtrl as app">
<h2>{{app.title}}</h2>
@alonronin
alonronin / index.html
Created June 3, 2015 20:37
Controlling a directive controller via service
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app="MyApp">
<div ng-controller="MyCtrl as ctrl">
<button ng-click="ctrl.invoke()">Invoke from controller</button>
@alonronin
alonronin / service.js
Created June 23, 2015 10:40
mocking promises $q.all using $scope.$apply()
+function(angular){
'use strict';
angular.module('app.services')
.service('MyService', function($q){
var self = this;
var a = function(){ return $q.when({}) };
var b = function(){ return $q.when({}) };
@alonronin
alonronin / recurssive.tree.js
Last active August 26, 2023 09:23
Create recursive tree from json using lodash transform without recursion. Can have unlimited nesting.
var _ = require('lodash');
var arr = [
{"name":"my2child1","title":"My 2 Child 1","parent":"my2"},
{"name":"my2child2","title":"My 2 Child 2","parent":"my2"},
{"name":"parent","title":"A single parent"},
{"name":"child-parent","title":"A child parent","parent":"child1"},
{"name":"my","title":"My"},
{"name":"my2","title":"My2"},
{"name":"child1","title":"Child 1","parent":"my"},