Skip to content

Instantly share code, notes, and snippets.

View kvendrik's full-sized avatar

Koen Vendrik kvendrik

View GitHub Profile
import AWS from 'aws-sdk';
export default class S3Upload {
constructor(options = {}) {
this._options = options;
}
_genRandStr(length = 41) {
// Math.random returns number with length between 16 and 18 chars
@kvendrik
kvendrik / api.rb
Last active August 31, 2016 21:19
Super Simple API Setup in Ruby + Curl Commands
require 'sinatra'
require 'json'
post '/' do
push = JSON.parse(request.body.read)
{ :body => push }.to_json
end
get '/:id?' do
content_type :json
@kvendrik
kvendrik / array.bash
Last active June 17, 2016 11:08
Bash CLI Parsing Options
#!/bin/bash
FLAGS=("verbose" "force")
ARGS=$@
# loop all arguments
for arg in "$@"
do
# check if arg is flag
@kvendrik
kvendrik / webhook.rb
Last active July 13, 2021 01:41
Simple Github Hook Receiver
require 'sinatra'
require 'json'
get '/' do
end
post '/payload' do
request.body.rewind
payload_body = request.body.read
@kvendrik
kvendrik / insertAtCaret.js
Last active August 7, 2016 19:10
es2015 version of insertAtCaret method
function insertAtCaret(text) {
const txtarea = document.activeElement;
const scrollPos = txtarea.scrollTop;
let strPos = 0;
const br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ));
if (br == "ie") {
txtarea.focus();
const range = document.selection.createRange();
@kvendrik
kvendrik / dataToggle.js
Created August 24, 2016 09:53
dataToggle.js
const dataToggle = {
init(){
this._els = document.querySelectorAll('[data-toggle]') || [];
this._bindEvents();
},
_bindEvents(){
[].forEach.call(this._els, (el) => {
el.addEventListener('click', () => this._toggleTarget(el), false);
@kvendrik
kvendrik / README.md
Created September 4, 2016 20:26
Hackbot - A Slack bot that helps with Hackathons

Show random giphy every x amount of time with keyword.

@hackbot cheer me up every 5 hours with kittens

askAll & askAllDM

Ask for teamname

hackBot.askAllDM([
@kvendrik
kvendrik / README.md
Created September 14, 2016 13:44
Slack Timezone Bot

Every time someone says something like "10am EST" it should show can time that is for people in different timezones like "10am EST (3pm GMT, 4pm CEST)".

@kvendrik
kvendrik / README.md
Last active September 21, 2016 17:03
Javascript with strict data types. Why? Cause reasons. WIP
Usage: jts <filename>
  • Check Literal Return Types
  • Check Method Call Argument Types
  • Check Dynamic Return Types (variables)
  • More data types (arrays etc.)
@kvendrik
kvendrik / Shortcuts.coffee
Created September 27, 2016 15:40
Shortcuts Lib
class Hottie
constructor: (config) ->
@_bindings = config.bindings;
@_waitForInputTime = config.waitForInputTime;
@_pressedKeys = '';
#bind keyup event
document.addEventListener('keyup', @_handleKey.bind(this), false);
_resetWaitInputTimer: (callback) ->