Skip to content

Instantly share code, notes, and snippets.

View nojvek's full-sized avatar

Noj Vek nojvek

View GitHub Profile
@nojvek
nojvek / ObjUtils.watch
Last active August 29, 2015 14:15
Simple javascript Object.watch
/*
MIT Licence
Copyright © 2015 Noj Vek
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
@nojvek
nojvek / watchAndReload.js
Last active September 25, 2015 01:25
LiveReload CSS
// Watch for changes and auto-reload
// CSS changes get auto injected, js changes reload current page
var pollInterval = 2; // check every 2 seconds
var jsMap = {"powerbi.js":null, "powerbicommon.js":null};
var cssMap = {"powerbi.css":null, "powerbicommon.css": null};
function getLastModifiedTime(url, callback) {
$.ajax({
type: "HEAD", // HEAD only gives headers, a lot faster
url: url,
@nojvek
nojvek / spaces2tabs.py
Created June 27, 2012 11:40
Convert Spaces to Tabs
import os
import re
#whatever filter you would like to apply
os.system('find * -type f | egrep -v ".svn" | egrep "\.(js|mustache|css|html|txt|less|sass|as|cfml|mxml)$" > /tmp/sourcefiles.txt')
with open('/tmp/sourcefiles.txt') as f:
files = f.read().strip().split("\n")
for file in files:
fs = require 'fs'
XXHash = require 'xxhash'
path = require 'path'
#dive = require 'dive'
HashStream = XXHash.Stream
c = console
startTime = Date.now()
mapFileName = 'pbix.json'
rootDir = '../pbix'
fs = require 'fs'
readline = require 'readline'
path = require 'path'
c = console
###
# Helpers
###
parseCliForPath = ->
@nojvek
nojvek / ufw.sh
Created April 17, 2016 18:38
Ubuntu Firewall Setup
sudo apt-get install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow 9000
sudo ufw allow 9001
sudo ufw allow 9002
sudo ufw status verbose
#sudo ufw enable
public render()
const todos = @.props.model.todos
let shownTodos = todos.filter (todo) ->
switch @.state.nowShowing
case ACTIVE_TODOS:
-< !todo.completed
case COMPLETED_TODOS:
-< todo.completed
default:
@nojvek
nojvek / PNGAlphaTrim.py
Created July 19, 2012 06:27
Trim transparency of all PNG files in a folder
import Image
import sys
import glob
# Trim all png images with alpha in a folder
# Usage "python PNGAlphaTrim.py ../someFolder"
try:
folderName = sys.argv[1]
except :
@nojvek
nojvek / droneseed.ts
Last active December 13, 2016 09:13
DroneSeed challenge
const MIN_HEIGHT = 4
const MAX_HEIGHT = 8
const HEIGHT_DELTA = MAX_HEIGHT - MIN_HEIGHT
interface Path {
startIndex: number
startHeight: number
endIndex: number
endHeight: number
}
@nojvek
nojvek / Object.map.js
Created February 22, 2017 02:02
Object.map
/**
* Suppose there was an Object.map function similar to Array.map
* There is some discussion about this on es-discuss but no one has filed a formal proposal yet (someone should!)
* @param {Object} object
* @param {function} callback
*/
Object.map = function(object, callback) {
if (!object) {
throw new TypeError(`object is null or not defined`);
}