Skip to content

Instantly share code, notes, and snippets.

View shrmnk's full-sized avatar
🏕️
working from home

Sherman K shrmnk

🏕️
working from home
View GitHub Profile
@jbielick
jbielick / git_sync.py
Last active October 11, 2023 09:02
an Apache Airflow DAG to sync a git repository to the google cloud storage bucket for your Composer environment
from datetime import datetime, timedelta
from airflow.models import Variable
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
private_key = Variable.get("git_deploy_private_key_secret")
repo_url = Variable.get("git_remote_url")
default_args = {
@Filirom1
Filirom1 / custom-logger.rb
Created January 12, 2017 14:41
How to customize a logger in ruby
require 'logger'
module Dim
class Logger < ::Logger
def initialize(*)
super
@formatter = NoTimestampFormatter.new
end
end
@the-bass
the-bass / application.html.erb
Last active April 15, 2020 15:01
Using Google Analytics with Rails 5 and Turbolinks 5. This code is taken from the conversation between @preetpalS and @packagethief on https://github.com/turbolinks/turbolinks/issues/73.
<%# Put this code snippet between the <head></head>-tags in your application layout and %>
<%# replace 'UA-XXXXXXXX-X' with your own unique Google Analytics Tracking ID %>
<%# ... %>
<head>
<%# ... %>
<% if Rails.env.production? %>
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@ajfisher
ajfisher / firmatatest.js
Last active December 22, 2019 08:15
Serial comms over hardware UART for Johnny-Five between Arduino and a Raspberry Pi
var firmata = require('firmata');
var repl = require('repl');
var board = new firmata.Board('/dev/ttyAMA0',function(err){
//arduino is ready to communicate
if (err) {
console.log("err:" + err);
return;
}
console.log("Firmata Firing LEDs");
@grenade
grenade / 01-generate-ed25519-ssh-key.sh
Last active May 25, 2024 05:56
generate ed25519 ssh and gpg/pgp keys and set file permissions for ssh keys and config
#!/bin/bash
# generate new personal ed25519 ssh key
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "rob thijssen <rthijssen@gmail.com>"
# generate new host cert authority (host_ca) ed25519 ssh key
# used for signing host keys and creating host certs
ssh-keygen -t ed25519 -f manta_host_ca -C manta.network
eval "$(ssh-agent -s)"
@choonkeat
choonkeat / singapore_license_plate_validator.rb
Created July 30, 2012 15:45
rails active_model validator for singapore nric & car plate; courtesy www.tinkerbox.com.sg
class SingaporeLicensePlateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[attribute] << (options[:message] || "is not valid") unless valid_format?(value)
end
def valid_format?(license_plate)
prefix, numbers, suffix = license_plate.to_s.upcase.gsub(/\W+/, '').scan(/^\s*([A-Z]{1,3})(\d{1,4})(.+)$/).flatten
license_plate = ('%3s' % prefix.to_s) + ('%4d' % numbers.to_i) + suffix.to_s
zero = ('A'.ord-1).chr
numbers = []
license_plate.each_char {|char| numbers.push((num = char.ord - zero.ord) > 0 ? num : char)}