Skip to content

Instantly share code, notes, and snippets.

View velocityzen's full-sized avatar
🚲
Inventing

Alexey Novikov velocityzen

🚲
Inventing
View GitHub Profile
@nossidge
nossidge / Snowball
Last active December 15, 2015 14:09
C++ Generate valid snowball poems, using input file of example text and Markov chains to help make it grammatically correct.
/*
~~ Snowball Poem ~~
Snowball (also called a Chaterism): A poem in which each line is a single word,
and each successive word is one letter longer. One of the constrained writing
techniques invented by the Oulipo (Workshop of Potential Literature).
~~ Program Description ~~
This program takes input from the file "input-raw.txt". It examines the file for
@LinusU
LinusU / uuid-v5.js
Created April 30, 2014 12:32
UUID V5 Node.js
function uuid5(data) {
var out = crypto.createHash('sha1').update(data).digest();
out[8] = out[8] & 0x3f | 0xa0; // set variant
out[6] = out[6] & 0x0f | 0x50; // set version
var hex = out.toString('hex', 0, 16);
return [
hex.substring( 0, 8),
@RTC1
RTC1 / gist:89d7f95555be8cf7d1aa
Created June 27, 2014 15:14
CacheBuster NGINX Rule 1
location ~* "^(.+)-[0-9a-f]{32}(\.(.*))$" {
try_files $uri $1$2 =404;
}
@renehuber
renehuber / gist:2959472
Created June 20, 2012 11:38
Plaintext contentEditable DIVs
/**
* Event handler to prevent richtext and linebreaks in contentEditable DIVs
*/
$('body').on('keydown paste', 'div.editfield', function(e) {
var $field = $(e.currentTarget);
if (e.keyCode===13 && $field.hasClass('multiline')) {
return true;
} else if (e.keyCode===13 || e.type==='paste') {
setTimeout(function() {
$field.html($field.text());
@eriwen
eriwen / cors.js
Created May 26, 2012 15:54
Simple cross-domain Javascript function
/**
* Make a X-Domain request to url and callback.
*
* @param url {String}
* @param method {String} HTTP verb ('GET', 'POST', 'DELETE', etc.)
* @param data {String} request body
* @param callback {Function} to callback on completion
* @param errback {Function} to callback on error
*/
function xdr(url, method, data, callback, errback) {
@b2arn
b2arn / puller
Created August 13, 2012 16:13
Script to git pull all repos in directory
#!/bin/bash
current_dir=`pwd`/
dir=$current_dir
usage="Usage : `basename $0` [-d dir] [-h] args\nWhere args are directories that you don't whant to pull"
while getopts hd: opt; do
case $opt in
d)
if [ ! -d "$OPTARG" ] ; then
@bendc
bendc / iterable.js
Created January 26, 2016 09:09
Make objects iterable
const iterable = function* (obj) {
yield* Object.keys(obj).map(key => [key, obj[key]]);
};
@JohnSundell
JohnSundell / Perform.swift
Last active December 21, 2019 14:43
A function that enables you to easily wrap throwing APIs, to provide a custom error
/**
* Perform a throwing expression, and throw a custom error in case the expression threw
*
* - parameter expression: The expression to execute
* - parameter error: The custom error to throw instead of the expression's error
* - throws: The given error
* - returns: The return value of the given expression
*/
func perform<T>(_ expression: @autoclosure () throws -> T, orThrow errorExpression: @autoclosure () -> Error) throws -> T {
do {
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
#define EPSILON 1.0e-5
#define RESOLUTION 32
class Point2D
@robertsdionne
robertsdionne / deepdream-install.md
Last active February 15, 2021 16:07
Deepdream installation
#!/usr/bin/env bash

# Assuming OS X Yosemite 10.10.4

# Install XCode and command line tools
# See https://itunes.apple.com/us/app/xcode/id497799835?mt=12#
# See https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcode-select.1.html
xcode-select --install