Skip to content

Instantly share code, notes, and snippets.

💭
Coding

Neo Liu diabloneo

💭
Coding
View GitHub Profile
View jekyll-and-liquid.md

Jekyll & Liquid Cheatsheet

A list of the most common functionalities in Jekyll (Liquid). You can use Jekyll with GitHub Pages, just make sure you are using the proper version.

Running

Running a local server for testing purposes:

@diabloneo
diabloneo / main.go
Created Jan 19, 2016
Execute command with timeout
View main.go
package main
import (
"fmt"
"os/exec"
"time"
)
func main() {
cmd := exec.Command("./pause1min")
@diabloneo
diabloneo / main.go
Last active Dec 9, 2016
Set array element of a JSON using go-simplejson
View main.go
package main
import (
"fmt"
"github.com/bitly/go-simplejson"
)
func testJsonArray1(pgStatsJson []*simplejson.Json) {
fmt.Println("testJsonArray1")
j := simplejson.New()
@diabloneo
diabloneo / 99
Created Mar 26, 2015
九九乘法表
View 99
[[y*x for x in range(1, y+1)] for y in range(1, 10)]
@diabloneo
diabloneo / queen.py
Created Mar 7, 2015
N Queens Problem -- in recursive method
View queen.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
count = 0
def can_place(board, n, row, col):
if any([board[i][col] for i in range(row)]
+ [board[row-i][col-i] for i in range(1, row+1) if col >= i]
+ [board[row-i][col+i] for i in range(1, row+1) if (col+i) < n]):
@diabloneo
diabloneo / Hello.java
Created Oct 22, 2014
Process home directory in Java.
View Hello.java
/**
* Created by diabloneo on 10/1/14.
*/
import java.io.IOException;
import java.util.Scanner;
import java.nio.file.Paths;
public class Hello {
@diabloneo
diabloneo / burn_cpu.sh
Created Sep 10, 2014
Make CPU usage 100%
View burn_cpu.sh
#!/bin/bash
cpunum=$(cat /proc/cpuinfo | grep 'processor' | wc -l)
for i in $(seq ${cpunum})
do
dd if=/dev/zero of=/dev/null &
done
@diabloneo
diabloneo / mac_exchange.sh
Last active Aug 29, 2015
Command line Python to exchange MAC address bytes.
View mac_exchange.sh
#!/bin/bash
mac="56:66:6c:03:ef:dc"
newmac=$(python -c "mac = \"${mac}\"; newmac=mac[0] + mac[16] + mac[2:]; print newmac")
echo ${newmac}
@diabloneo
diabloneo / timespec_diff.c
Created Mar 18, 2014
Calculate diff of two struct timespec
View timespec_diff.c
#include <time.h>
void timespec_diff(struct timespec *start, struct timespec *stop,
struct timespec *result)
{
if ((stop->tv_nsec - start->tv_nsec) < 0) {
result->tv_sec = stop->tv_sec - start->tv_sec - 1;
result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000;
} else {
result->tv_sec = stop->tv_sec - start->tv_sec;
@diabloneo
diabloneo / rds_authenticator.py
Created Sep 2, 2013
Calculate RADIUS packet authenticator. Input packet's hex string, output authenticator in hex form.
View rds_authenticator.py
#!/usr/bin/env python
import hashlib
import base64
import binascii
def main():
pktstr = raw_input()
m = hashlib.md5()
m.update(base64.b16decode(pktstr.replace(' ', '').upper()))
You can’t perform that action at this time.