Skip to content

Instantly share code, notes, and snippets.

@yinyin
yinyin / optional_parameter.dart
Last active June 14, 2017 19:16
Dart optional function parameter experiment
void namedParameter(String param1, String param2,
{bool enable, bool bold = false, bool hidden = false}) {
print("namedParameter:param1=${param1}");
print("namedParameter:param2=${param2}");
print("namedParameter:enable=${enable}");
print("namedParameter:bold=${bold}");
print("namedParameter:hidden=${hidden}");
print("--");
}
@yinyin
yinyin / socketpair_example.c
Created May 27, 2017 10:13
Example of socketpair() function
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
void parent_process(int fd) {
int i;
fprintf(stderr, "FD of parent process: %d.\n", fd);
@yinyin
yinyin / mro_exp.py
Last active May 20, 2017 11:37
Python MRO Experiment
# -*- coding: utf-8 -*-
""" MRO Experiment
$ python -i mro_exp.py
>>> a = GD1(1, 2, 3, 4, 5, 6, 7, 8)
_Base(*args=(), **kwds={})
CL3(cparam3a=7, cparam3b=8, *args=(), **kwds={})
@yinyin
yinyin / env-autotools.sh
Last active December 4, 2018 23:56
Set environment variables for autotools
#!/bin/bash
# source ~/bin/env-autotools.sh
OPT_BASE=/opt
which autoreconf
if [ "$?" != "0" ]; then
export PATH=${OPT_BASE}/autoconf-2.69/bin:$PATH
fi
@yinyin
yinyin / loop.sh
Created November 13, 2016 08:43
Print a fixed text and current time every 3 seconds
#!/bin/bash
while true; do
echo "Press [CTRL+C] to stop.."
/bin/date
sleep 3
if [ "$?" == "1" ]; then
break
fi
done
@yinyin
yinyin / mysqlnowspeed.go
Last active May 1, 2018 13:40
Test mysql link speed over various DSN with SELECT NOW()
// Test mysql speed over various DSN with SELECT NOW()
//
// Build with:
// // make an empty folder and cd into
// export GOPATH=`pwd`
// go get gist.github.com/e792f270bb6bc93a2a671bb7519d5417.git
// // or, for cross-build:
// env GOOS=linux GOARCH=amd64 go build -v gist.github.com/e792f270bb6bc93a2a671bb7519d5417.git
package main
sudo apt-get remove binutils cpp cpp-4.8 cpp-4.9 dkms fakeroot gcc gcc-4.8 gcc-4.9 libasan0 libasan1 libatomic1 libc-dev-bin libc6-dev libcilkrts5 libcloog-isl4 libfakeroot libgcc-4.8-dev libgcc-4.9-dev libgomp1 libisl10 libitm1 liblsan0 libmpc3 libmpfr4 libquadmath0 libtsan0 libubsan0 linux-compiler-gcc-4.8-x86 linux-headers-3.16.0-4-amd64 linux-headers-3.16.0-4-common linux-headers-amd64 linux-kbuild-3.16 linux-libc-dev make manpages-dev open-vm-tools-dkms patch
@yinyin
yinyin / genpassword.go
Created October 31, 2015 16:46
Function to generate random password
import "time"
import "math/rand"
func init() {
rand.Seed(time.Now().Unix())
}
func GenerateRandomPassword(length int) string {
const base_string = "2346789BCDFGHJKMPQRTVWXY"
const l_base_string = len(base_string)
@yinyin
yinyin / TestWindow.java
Created September 12, 2015 04:56
Template code generated with WindowBuilder's SWT > ApplicationWindow
package local.dev;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TestWindow {
protected Shell shell;
#!/bin/bash
MVN_HOME=/.../apache-maven-3.3.3
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre
exec $MVN_HOME/bin/mvn "$@"