Skip to content

Instantly share code, notes, and snippets.

View nickaigi's full-sized avatar
🚀
To the Moon

Nickson Kaigi nickaigi

🚀
To the Moon
View GitHub Profile
@dhh
dhh / linux-setup.sh
Last active May 23, 2024 23:31
linux-setup.sh
# CLI
sudo apt update -y
sudo apt install -y \
git curl fzf eza \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
libssl-dev libreadline-dev zlib1g-dev libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev libjemalloc2 \
libvips imagemagick libmagickwand-dev mupdf mupdf-tools \
redis-tools sqlite3 libsqlite3-0 libmysqlclient-dev \
rbenv apache2-utils
@chelseadole
chelseadole / duplicate_to_partitioned_table.sql
Created October 1, 2023 19:36
plpgsql function returning a trigger which duplicates INSERT/UPDATE/DELETE activity to a second partitioned table. Requires inputting correct table names & column values for use.
-- This function is designed to duplicate all live INSERTS/UPDATES/DELETES from one table (referred to as "source_table_name"
-- to a second partitioned table (referred to as "destination_table_name"). The function should be set to trigger after insert/
-- update/delete on the source table.
-- This function is designed to be leveraged for partitioned table migration through this method:
-- 1) Create an empty partitioned copy of the "source_table_name". Alter primary key as necessary, as partitioned Postgres
-- tables do not support unique/primary keys not included in the partition key.
-- 2) Create the following function, and attach it as a trigger to "source_table_name". At this point, incoming new DML is
-- being copied successfully to the partitioned table, so only historical data will need to be backfilled.
-- 3) Target rows in "source_table_name" with an updated_at value BEFORE the trigger was attached, and backfill them into
@devhero
devhero / py_remote_extract_tar_gzip.py
Last active May 24, 2023 18:50
python download and extract remote file tar.gzip
# Instruct the interpreter to create a network request and create an object representing the request state. This can be done using the urllib module.
import urllib.request
import tarfile
thetarfile = "http://file.tar.gz"
ftpstream = urllib.request.urlopen(thetarfile)
thetarfile = tarfile.open(fileobj=ftpstream, mode="r|gz")
thetarfile.extractall()
# The ftpstream object is a file-like that represents the connection to the ftp server. Then the tarfile module can access this stream. Since we do not pass the filename, we have to specify the compression in the mode parameter.
@nickaigi
nickaigi / Ubuntu + Python + Postgres Setup.md
Last active August 29, 2015 14:00
Prepare a clean Ubuntu installation for Python development with PostgreSQL
  • Update and Upgrade the server

      $ sudo apt-get update && sudo apt-get upgrade
    
  • Follow instructions to add user ubuntu and grant ubuntu root priviledges

  • Install openssh-server

      $ sudo apt-get install openssh-server
    
@wingeng
wingeng / iterator.lua
Last active November 7, 2018 07:29
Description of making a stateless iterator for Lua.
-- The section describing iterators was configusing to me. http://www.lua.org/pil/7.1.html
--
-- I think it simpler to describe the 'stateless' iterator first, then
-- go into the nitty details of a 'stateful' iterator using closures.
--
--
-- Example of making an iterator in lua
--
-- The 'real' syntax for the 'for' statement is this
-- for <v> in <iter-fn>, <thing_2_iterate>, <initial-key> do
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 23, 2024 18:01
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@mshafrir
mshafrir / states_hash.json
Created May 9, 2012 17:05
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@simoncoulton
simoncoulton / nginx-uwsgi-python3
Created May 7, 2012 04:39
Setting up Nginx, uWSGI & Python3
======================================
Setting up Nginx, uWSGI and Python3
======================================
First off, I'm traditionally a PHP developer, but am looking at moving across to Python. I really struggled to find decent documentation on how to get a server up and running for deploying Python web applications from the point of view of someone coming from PHP. The main problems I came across with documentation were:
1) Only showed you how to run the server for a single web application.
2) Only showed you how to configure the app, not the server it was running on.
My preferred workflow for development is by setting up a new VM in VMware Fusion and then forwarding through all requests to that VM via /etc/hosts. This might not be the optimal way to get things up and running, but it works for me.
@whyisjake
whyisjake / arduino_robot
Created April 10, 2012 20:35
Arduino Robot Code
/*
Original code by Nick Brenn
Modified by Marc de Vinck
Make Projects Arduino-based 4WD robot
http://makeprojects.com/Project/Build-your-own-Arduino-Controlled-Robot-/577/1
*/
#include <AFMotor.h>
AF_DCMotor motor1(1, MOTOR12_8KHZ);
AF_DCMotor motor2(2, MOTOR12_8KHZ);
AF_DCMotor motor3(3, MOTOR12_1KHZ);
@brandonaaskov
brandonaaskov / jQuery Change Event: Proper Binding
Created January 11, 2012 21:34
jQuery's change() event doesn't work as expected with input text fields. This, however, does work.
/*
For some reason, the change() event only fires when the input field loses focus.
Binding to other options ('change keypress paste focus textInput input') will
fire the event several times, which is bad. The below code works even when
content is pasted into the text field, and only fires once as expected.
*/
$('#search-form .term').bind('input', function(){
console.log('this actually works');
});