Skip to content

Instantly share code, notes, and snippets.

View devm33's full-sized avatar

Devraj Mehta devm33

View GitHub Profile
@devm33
devm33 / date_local.js
Created March 9, 2014 09:27
Puts the local time date in a format the W3 is happy with. Disclaimer, I was not made any happier by writing this.
var zeroPad = function(str) {
return ('0'+ str).slice(-2);
};
var dateLocal = function() {
var d = new Date();
var s = d.getFullYear() + '-';
s += zeroPad(d.getMonth()) + '-';
s += zeroPad(d.getDate()) + 'T';
s += zeroPad(d.getHours()) + ':';
s += zeroPad(d.getMinutes()) + ':';
@devm33
devm33 / local.js
Last active August 29, 2015 13:58
Quickly serve a static folder using express
/* Set up a local testing server to serve a static folder */
var express = require("express");
express().use(express.static(__dirname)).listen(5000, function(){
console.log('http://0.0.0.0:5000 listening...');
});
/*
* robotMaze.js
*
* The blue key is inside a labyrinth, and extracting
* it will not be easy.
*
* It's a good thing that you're a AI expert, or
* we would have to leave empty-handed.
*/
@devm33
devm33 / reverse_polish.js
Created May 14, 2014 04:31
Reverse Polish Notation Calculator
function calc(expr) {
return expr.split(/\s+/).reduce(function(stack, current){
var a, b, c;
if(/[+\-*\/]/.test(current)){
b = stack.pop();
a = stack.pop();
switch(current) {
case '+': c = a + b; break;
case '-': c = a - b; break;
case '*': c = a * b; break;
@devm33
devm33 / exmachina.py
Created August 31, 2015 04:42
code displayed in ex machina
def sieve(n):
x = [1]*n
x[1] = 0
for i in range(2, n/2):
j = 2*i
while j<n:
x[j] = 0
j = j+i
return x
@devm33
devm33 / dynAttrs.js
Created September 13, 2015 16:55
angular directive to add/remove attributes like ngClass
angular.module('dynAttrs', [])
.directive('dynAttrs', () => {
return {
link: function(scope, element, attrs) {
scope.$watch(attrs.dynAttrs, (dynAttrs) => {
_.each(dynAttrs, (val, attr) => {
if(val) {
element.attr(attr, val);
} else {
element.removeAttr(attr);
@devm33
devm33 / shell_well.sh
Last active October 10, 2015 22:12
Doing things well in shell
# Display summarized (s) human-readable (both h) sizes of sub-directories sorted descending
# - remove / to include files in that folder
# - remove r to sort ascending by size
du -sh */ | sort -hr
# Remove broken symlinks (leverages zsh)
rm -- *(-@D)

Keybase proof

I hereby claim:

  • I am devm33 on github.
  • I am devm33 (https://keybase.io/devm33) on keybase.
  • I have a public key whose fingerprint is FB74 6ADC B899 CB2B E4C3 A712 E385 2F90 A94F A38B

To claim this, I am signing this object:

@devm33
devm33 / onename_verification.txt
Created October 10, 2017 21:21
onename verification
Verifying that "devm33.id" is my Blockstack ID. https://onename.com/devm33
@devm33
devm33 / gitpush.conf
Last active October 11, 2017 00:04
Monitor directory for deletion and then push.
[program:gitpush]
command=/home/devm33/gitpush.sh
autostart=true
autorestart=true
startretries=3
stderr_logfile=/var/log/gitpush.err.log
stdout_logfile=/var/log/gitpush.out.log
user=devm33