Skip to content

Instantly share code, notes, and snippets.

View Jamesits's full-sized avatar

Jamesits Jamesits

View GitHub Profile
@Jamesits
Jamesits / josephus-ring.c
Last active July 10, 2016 03:08
C program for solving Josephus Ring.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
// input arguments (assuming n, k > 0)
int n, k;
scanf("%d%d", &n, &k);
// initialize number -> position mapping array
@Jamesits
Jamesits / 8queen.py
Last active April 10, 2016 14:28
8 Queen Problem, Python 3
#!/usr/bin/env python3
# 8 Queens Problem
# by James Swineson
from functools import reduce
# 一个棋盘的表示,其中 .board[i] 表示第 i 行的旗子在第几列
class nQueenBoard:
def __init__(self, size, board=[]):
self.size = size
@Jamesits
Jamesits / update-everything.sh
Last active March 12, 2016 02:40
Functions for updating and upgrading everything.
#!/usr/bin/env bash
update() {
case $1 in
# apt-get
apt)
apt update && apt full-upgrade -y
;;
#!/usr/bin/env bash
# dotfiles utility - https://gist.github.com/Jamesits/9bc4adfb1f299380c79e
# Set $DOTFILES to where you want to put your dotfiles.
# then run dotfiles-init someSoftware,
# and it will move all files starting with `.someSoftware` to the correct location
# then link them back,
# Which will produce a directory structure like:
#
# $ tree -aL 2 ~/Dropbox/Code/config/dotfiles/
@Jamesits
Jamesits / esp12e-blink.ino
Last active September 24, 2020 03:22
Blink for ESP8266 ESP-12E NodeMCU 1.0 Board, Arduino IDE: Hello world and function tests.
#include <iostream>
#include <regex>
#include <fstream>
#include <string>
using namespace std;
int main() {
std::ifstream ifs("sample.in");
std::string var((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
@Jamesits
Jamesits / py-gene-t-tester.py
Last active January 27, 2016 16:04
This script has been used to analysis some gene test result in "tab separated value" format from some lab of ZJU. It saves tons of silly people's labor pasting two rows from two different xlsx to graphpad, click some analysis button and copy result back to the third xlsx. However, there is a drawback of this script: it's not parallel.
#!/usr/bin/env python3
# James' Gene T-tester
# Written by James Swineson <jamesswineson@gmail.com>, 2016-01-27
# All rights reserved.
#
# Install dependencies:
# pip3 install numpy scipy
#
# Tested to work under Python 3.5.1 on OS X 10.11.3
@Jamesits
Jamesits / string-padding.js
Last active January 20, 2016 08:45
String padding for JavaScript: Make a string fixed length by adding blank chars before or after it.
/*
String padding
by James Swineson (@Jamesits)
https://gist.github.com/Jamesits/30acd725d5fdfb67eae4
Make a string fixed length by adding blank chars between or after it.
Usage:
"123".lpadding(5) // returns " 123"
"123".lpadding(5, "0") // returns "00123"
"123".lpadding(2) // returns "23"
"123".rpadding(5) // returns "123 "
@Jamesits
Jamesits / update.sh
Created October 13, 2015 13:58
Update dnsmasq additional hosts file on OpenWRT from https://github.com/StevenBlack/hosts
#!/bin/bash
echo "Updating hosts..."
wget --show-progress -O hosts -- https://github.com/StevenBlack/hosts/raw/master/hosts && /etc/init.d/dnsmasq restart
echo "Update finished. "
@Jamesits
Jamesits / loveometer.ino
Created October 13, 2015 09:08
Love-o-meter Arduino Project rewritten
// Love-o-meter rewritten code
// by James Swineson, 2015-10-13
// For demonstration use only.
// =========== Settings ===========
// Total LED number
#define LEDCOUNT 5
// Which digital pins are LEDs connected to. They will light up from left to right.