Skip to content

Instantly share code, notes, and snippets.

View 607011's full-sized avatar
๐Ÿ
Yes, please?!

Oliver Lau 607011

๐Ÿ
Yes, please?!
View GitHub Profile
@607011
607011 / backup.sh
Last active July 11, 2017 07:08
Get a password from the macOS key chain
#!/bin/bash
SRCDIR=$HOME/PUT_SOURCE_DIRECTORY_HERE
DSTDIR=$HOME/PUT_DESTINATION_DIRECTORY_HERE
REMOTE_SHARE=PUT_SERVER_NAME_HERE/PUT_NAME_OF_SHARE_HERE
KEYCHAIN_SERVICE_TOKEN=CHANGE_TO_NAME_OF_SERVICE_AS_STORED_IN_KEYCHAIN
USERNAME=ola
PASSWORD=$(security find-generic-password -s $KEYCHAIN_SERVICE_TOKEN -w)
if [ ! -d "$DSTDIR" ]; then
@607011
607011 / post-receive
Created April 14, 2016 12:07
Git post-receive hook to deploy latest release to a given directory
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os, subprocess
from datetime import datetime
oldrev, newrev, branch = sys.stdin.read().split()
refs, head, branch = branch.split('/')
deploy_to = None
@607011
607011 / Hammering element (CSS)
Created March 24, 2016 13:34
Styles for "hammering" element
@keyframes hammer {
from,20%,53%,80%,to {
-webkit-animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0)
}
40%,43% {
-webkit-animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
@607011
607011 / convert-to-video.py
Created January 28, 2016 13:13
Convert screencast from Microsoft Expression Encoder to mp4 and webm, extract a thumbnail at 75% of playtime
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, subprocess
from os import chdir
from glob import glob
FFMPEG = 'D:\\Developer\\ffmpeg.exe'
FFPROBE = 'D:\\Developer\\ffprobe.exe'
@607011
607011 / 2d-arr.py
Created December 27, 2015 18:22
Generate 2D array of width w and height h
result = [a[:] for a in [[' '] * h] * w]
@607011
607011 / generate.cpp
Created April 21, 2015 08:30
Warming up and using the Mersenne-Twister
#include <string>
#include "mt.h"
warmupRNG();
std::uniform_int_distribution<int> rollTheDice(1, 6);
for (int i = 0; i < 1000; ++i)
std::cout << rollTheDice(gRNG()) << ", ";
@607011
607011 / gist:05e09c0d0a7c5510125c
Last active August 29, 2015 14:17
Create new Windows-GUID as std::string
std::string createGUIDString(void) {
GUID guid;
HRESULT hCreateGuid = CoCreateGuid(&guid);
std::stringstream strBuf;
strBuf << std::hex << std::setw(8) << std::setfill('0')
<< guid.Data1 << "-" << guid.Data2 << "-" << guid.Data3 << "-";
for (int i = 0; i < 2; ++i)
strBuf << std::hex << std::setw(2) << std::setfill('0') << short(guid.Data4[i]);
strBuf << "-";
for (int i = 2; i < 8; ++i)
@607011
607011 / gist:6893a238c17e4ffa3707
Created February 13, 2015 12:40
BoolTranslator for boost::property_tree::ptree
#include <boost/algorithm/string/predicate.hpp>
struct BoolTranslator
{
typedef std::string internal_type;
typedef bool external_type;
// Converts a string to bool
boost::optional<external_type> get_value(const internal_type& str)
{
@607011
607011 / fisher-yates-shuffle.cpp
Last active October 20, 2015 15:38
Fisher-Yates-Shuffle (shuffling of array elements)
// using Qt
QByteArray shuffled(const QByteArray &ba)
{
QByteArray result = ba;
int n = result.count();
char *c = result.data();
while (n) {
int j = qrand() % n--;
char tmp = *(c + n);
@607011
607011 / cleartype.ps1
Created May 27, 2014 12:31
Cleartype on/off
param([bool]$enable)
$signature = @'
[DllImport("user32.dll")]
public static extern bool SystemParametersInfo(
uint uiAction,
uint uiParam,
uint pvParam,
uint fWinIni);
'@