Skip to content

Instantly share code, notes, and snippets.

View samkahchiin's full-sized avatar
🎯
Focusing

Sam Kah Chiin samkahchiin

🎯
Focusing
View GitHub Profile
class Sudoku
def initialize(board_string)
p "Start game!"
board(board_string)
end
def solve!(string)
create_string_array(string)
@samkahchiin
samkahchiin / kill_port
Created February 22, 2018 08:48
Kill the process running on certain port
# Eg. PORT_NUMBER -> 3000
kill -9 $(lsof -t -i:PORT_NUMBER -sTCP:LISTEN)
@samkahchiin
samkahchiin / pre-commit
Created February 12, 2018 03:11
A pre-commit hook which will rubocop or coffeelint the respective file
#!/usr/bin/env ruby
require "english"
require "rubocop"
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
file_list = `git status --porcelain`.split(/\n/)
file_list = file_list.select do |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
@samkahchiin
samkahchiin / git-remove-non-active-local-branch
Last active February 18, 2019 04:10
Remove all local branch except the first 10 most active
git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads > all | head -n 10 > first-10
diff first-10 all | sed "s/> refs\/heads\///g" | xargs git branch -D | rm all | rm first-10
@samkahchiin
samkahchiin / octave.md
Last active September 27, 2017 14:39 — forked from obstschale/octave.md
An Octave introduction cheat sheet.

Octave CheatSheet

GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
(via GNU Octave)

Basics

  • not equal ~=
  • logical AND &&
@samkahchiin
samkahchiin / form-submission-handler.js
Last active August 27, 2017 09:50
A function copied from dwyl/html-form-send-email-via-google-script-without-server
function validEmail(email) { // see:
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(email);
}
function validateHuman(honeypot) {
if (honeypot) { //if hidden form filled up
console.log("Robot Detected!");
return true;
} else {
# move all files from current directory to upper directory
mv * ../
# copy all files in 'a' folder to 'b' folder
cp -a /a/. /b/
@samkahchiin
samkahchiin / macvim
Last active September 30, 2023 22:15
- How to set the default font size in macvim
# Open Terminal
vim ~/.vimrc
# Mac OS-X -> .vimrc ; Window -> .gvimrc
# Add it in the file and adjust the font size (h12) accordingly
set guifont=Menlo\ Regular:h15
@samkahchiin
samkahchiin / Heroku PGBackups
Last active May 27, 2016 00:46
Backing up data from heroku
# Do this to ensure that you still can safely return to the original state if the deploy is unsuccessful
APPNAME=production
# Backing up the data from production (or apps name) to your heroku dashboard
heroku pg:backups capture -r APPNAME
# Downloading the data from the heroku dashboard to local machine
curl -o {PATHNAME}.dump `heroku pg:backups public-url -r APPNAME`
function pairwise(arr, arg) {
var ans = [];
for(var i = 0; i < arr.length ; i++){
var elem = arr.shift();
var pairElemIndex = arr.indexOf(arg - elem);
if( pairElemIndex !== -1 ){
ans.push(i,pairElemIndex + i + 1);
delete arr[pairElemIndex];
}
}