Skip to content

Instantly share code, notes, and snippets.

View kvendrik's full-sized avatar

Koen Vendrik kvendrik

View GitHub Profile
@kvendrik
kvendrik / readme.md
Last active August 29, 2015 14:06
Test path in object

Instead of this:

if( person !== undefined && person.details !== undefined && person.details.city !== undefined )

Using this method you can use this:

if( person.testPath('details.city') )
@kvendrik
kvendrik / mixins.scss
Last active August 29, 2015 14:06
Simple SASS boilerplate (mixins and variables)
//Border
@mixin border($side:false, $color:$grey-light){
@if $side {
border-#{$side}: $border-style $border-width $color;
} @else {
border: $border-style $border-width $color;
}
}
//Prefix property
@kvendrik
kvendrik / GruntFile.js
Last active August 29, 2015 14:06
Simple Grunt boilerplate
module.exports = function (grunt){
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
appRoot: 'app',
connect: {
server: {
@kvendrik
kvendrik / parse-includes.js
Last active August 29, 2015 14:06
Grunt include tag parser
grunt.registerTask('parse-includes', 'Parse include tags in HTML files', function(){
//projects root and
//HTML files folder
var basePath = 'public/',
viewsDir = 'views/',
//get all HTML files in folder
htmlFiles = grunt.file.expand(basePath+viewsDir+'*.html'),
currFileContents;
@kvendrik
kvendrik / genrandstr.js
Last active October 1, 2017 19:01
Generate a random string with a fixed length
function genRandStr(length = 41){
// Math.random returns number with length between 16 and 18 chars
// if length below 16 do in one go
if (length <= 16) {
return Math.random().toString(36).substring(2,length+2);
}
// else calculate how many iterations we need
const iterations = Math.ceil(length / 16);
let outputStr = '';
@kvendrik
kvendrik / decorators-example.py
Last active August 29, 2015 14:08
Just a simple decorators example
def makeAwesome(sayFunc):
def wrapper(*args):
print sayFunc(args[0]+" are awesome")
return wrapper
@makeAwesome
def say(name):
print name
"""
Equal to: makeAwesome(say), this returns wrapper.
@kvendrik
kvendrik / exceltojson.py
Last active August 29, 2015 14:08
Simple Excel to JSON converter
import xlrd
import json
import os.path
class ExcelToJson:
def convertFile(self, filePath, sheetName=None):
if not os.path.isfile(filePath):
print filePath+' does not exist or is not a file'
@kvendrik
kvendrik / parse_options.rb
Created November 4, 2014 15:02
Ruby class to parse command line arguments (Ruby practise)
=begin
Class that parses command line arguments
@author Koen Vendrik <k.vendrik@gmail.com>
@date November 2014
=end
=begin
Simple Usage:
require_relative 'parse_args'
@kvendrik
kvendrik / binary-text-converter.rb
Last active August 29, 2015 14:08
Simple Binary - Text converter (Ruby practise)(Can be done more easily using Ruby's `pack` and `unpack`)
class BinaryText
@eight_bit_nums = [128, 64, 32, 16, 8, 4, 2, 1]
def self.binaryToText(binary)
groups = binary.scan(/.{8}/)
resultStr = ''
# loop through groups of 8
groups.each do |group|
@kvendrik
kvendrik / crypt-string.c
Last active August 29, 2015 14:09
Harvard CS50 Problem Sets
int cryptString (int argc, char* argv[]){
char* s = argv[1];
for(int i = 0; i < strlen(s); i++){
int newAscii = (s[i]+6 > 122 ? ((s[i]+6)%122)+96 : s[i]+6);
printf("%c", newAscii);
}
}