Skip to content

Instantly share code, notes, and snippets.

@saetia
saetia / gist:1623487
Last active March 19, 2024 15:21
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
@saetia
saetia / web_image.rb
Last active November 26, 2022 03:17
Save web image as wallpaper
#/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('https://medium.com'))
urls = doc.at_css('.cover-img')["style"].scan(/\('([^\)]*)'\)/)
image_src = 'http:'+urls[0][0]
ext = image_src.split('.').last
random = rand(2**256).to_s(36)[0..7]
download_path = "/tmp/#{random}.#{ext}"
@saetia
saetia / .zshrc
Last active November 23, 2022 09:50
Zsh settings
ZSH=$HOME/.oh-my-zsh
ZSH_THEME="kphoen"
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
@saetia
saetia / 400.html
Created March 29, 2016 15:37
Errors
<!doctype html>
<html>
<title>400 Error</title>
<style>
body{text-align:center;position:absolute;width:100%;top:50%;left:50%;-webkit-transform:translate(-50%,-50%);-moz-transform:translate(-50%,-50%);transform:translate(-50%,-50%);}
h2,h3{color:#555;font:bold 200%/100px sans-serif;margin:0}
h3,p{color:#777;font:normal 150% sans-serif}
p{font-size: 100%;font-style:italic;margin-top:2em;}
</style>
<h2>we didn't understand the request</h2>
@saetia
saetia / is_federal_holiday.php
Last active August 31, 2019 00:03
is_federal_holiday
<?php
function is_federal_holiday(DateTime $date){
$year = $date->format('Y');
$federal_holidays = array_map(function($date_string) use($year){
$date = new DateTime($date_string . ' ' . $year);
if ($date->format('l') === 'Saturday') $date->modify('-1 day');
if ($date->format('l') === 'Sunday') $date->modify('+1 day');
return $date;
}, [
"january 1", //new year's day
@saetia
saetia / readme.md
Created June 16, 2019 21:31 — forked from xem/readme.md
Maths & trigonometry cheat sheet for 2D & 3D games

Conventions

  • A = [xA, yA] is a point on the 2D plane. Same for B, C, ...
  • lengths are in any unit (ex: pixels)
  • code snippets are in JavaScript

Degrees to radians

angleRad = angleDeg * Math.PI / 180;

@saetia
saetia / google-analytics-0.1.js
Created June 26, 2012 18:19
Google analytics
function initializeGoogleAnalytics(){
GoogleAnalytics.init();
}
var GoogleAnalytics = {
accountId: null,
accessToken: null,
getAccountId: function(){
return (this.accountId) ? 'ga:'+this.accountId : null;
@saetia
saetia / parse.rb
Last active June 26, 2017 16:59
Parse MySQL dumps
ruby -e "$(curl -fsSkL https://gist.githubusercontent.com/saetia/2369908/raw/4bf9a6d36060582e69f02c314f66449971a7bb11/parse.rb)" /Users/Joel/site.db.121010.dump
ruby parse.rb site.120411.dump
@saetia
saetia / findin.sh
Last active April 15, 2016 20:32
findin
#!/bin/bash
if [ $# -eq 0 ]; then
echo -e "Usage: $0 site.com \033[32m'alert'\033[0m js"
exit
fi
if [ ! -d /var/www/${1}/public ]; then
echo -e "\033[31mfailed:\033[0m ${1} does not exist"
exit
@saetia
saetia / gist:8570871
Last active January 4, 2016 04:49
Mysql triggers
CREATE TRIGGER `pages_created_at` BEFORE INSERT ON `pages` FOR EACH ROW SET NEW.created_at = UTC_TIMESTAMP(), NEW.updated_at = UTC_TIMESTAMP(), NEW.deleted_at = IF(NEW.deleted_at = "0000-00-00 00:00:00", NULL, NEW.deleted_at)
CREATE TRIGGER `pages_updated_at` BEFORE UPDATE ON `pages` FOR EACH ROW SET NEW.updated_at = UTC_TIMESTAMP(), NEW.created_at = OLD.created_at, NEW.deleted_at = IF(NEW.deleted_at = "0000-00-00 00:00:00", NULL, NEW.deleted_at)