Skip to content

Instantly share code, notes, and snippets.

View samkahchiin's full-sized avatar
🎯
Focusing

Sam Kah Chiin samkahchiin

🎯
Focusing
View GitHub Profile
@samkahchiin
samkahchiin / Google Form
Created April 17, 2020 05:26
Send email to Gmail after user submit a google form responses
function onFormSubmit(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var row = sheet.getLastRow();
var receiptId = row - 1;
sheet.getRange(row,6).setValue(receiptId);
var user = {receiptId: receiptId, name: e.namedValues['Name'][0], email: e.namedValues['Email'][0], amount: e.namedValues["Donation Amount"][0]};
sendDoc_(user);
}
function sendDoc_(user) {
@samkahchiin
samkahchiin / dharma-audio.rb
Created November 4, 2019 12:59
First attempt to use google speech
require "google/cloud/storage"
require "google/cloud/speech"
# puts "Your project id?"
# project_id = gets.chomp
#
# puts "Your bucket name?"
# bucket_name = gets.chomp
puts "File name?"
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