Skip to content

Instantly share code, notes, and snippets.

View allenyllee's full-sized avatar

Allen.YL allenyllee

View GitHub Profile
@bennadel
bennadel / jquery.event-trace.js
Created June 27, 2012 15:04
Tracing Event Binding And Event Triggering In jQuery
// Create a private scope.
(function( $, on ){
// I proxy the given function and return the resultant GUID
// value that jQuery has attached to the function.
var createAndReturnProxyID = function( target ){
// When generating the proxy, it doesn't matter what the
// "context" is (window in this case); we never actually
@lentschi
lentschi / xsudo.sh
Last active July 29, 2020 22:32
Run a program requiring xserver as another user by passing on the xauth cookie
#!/bin/bash -e
# Run a program requiring xserver as another user by passing on the xauth cookie
# s. http://askubuntu.com/questions/871092/failed-to-connect-to-mir-failed-to-connect-to-server-socket-no-such-file-or-di?newreg=811c7a1d637341c5b294d8b515e8b6e7
# s. http://serverfault.com/questions/51005/how-to-use-xauth-to-run-graphical-application-via-other-user-on-linux
# AUTHOR: Florian Lentsch <office@florian-lentsch.at>
# TESTED: on Ubuntu 16.04 only
#
# USAGE: xsudo <username> <command>
@super3
super3 / payout.MD
Last active September 8, 2020 01:48
Storj Bridge Payout Formula

Payout Formula

paymentModelFunction = function(gbHours, telemReports, downloadedBytes) {
 gbHoursScaled =  (gbHours - mean(gbHours)) / sd(gbHours)
 telemReportsScaled =  (telemReports - mean(telemReports)) / sd(telemReports)
 downloadedBytesScaled = (downloadedBytes - mean(downloadedBytes)) / sd(downloadedBytes)
 
 basePayout = 10
 ghHourPayout = 12.2221 * gbHoursScaled
 telemReportsPayout = 0.1452 * telemReportsScaled
@dnephin
dnephin / common.env
Last active January 7, 2022 06:48
docker-compose extends and environment variables
TEST_ONE=common-env-file
TEST_TWO=common-env-file
TEST_TREE=common-env-file
TEST_FOUR=common-env-file
@gvolpe
gvolpe / shared-state-in-fp.md
Last active March 15, 2022 20:27
Shared State in pure Functional Programming

Shared State in pure Functional Programming

Newcomers to Functional Programming are often very confused about the proper way to share state without breaking purity and end up having a mix of pure and impure code that defeats the purpose of having pure FP code in the first place.

Reason why I decided to write up a beginner friendly guide :)

Use Case

We have a program that runs three computations at the same time and updates the internal state to keep track of the

@ojdo
ojdo / pandas-to-excel.py
Last active April 12, 2022 10:47
From Pandas to Excel using Openpyxl
import pandas as pd
from io import StringIO
from openpyxl.formatting.rule import ColorScaleRule
from openpyxl.styles import Alignment, Font, NamedStyle
from openpyxl.utils import get_column_letter
df = pd.read_csv(StringIO("""\
alpha beta gamma
2000-01-01 -0.173215 0.119209 -1.044236
2000-01-02 -0.861849 -2.104569 -0.494929
@dooglus
dooglus / public.py
Created August 13, 2016 20:45
create Bitcoin public key from private key
#! /usr/bin/env python
class Point(object):
def __init__(self, _x, _y, _order = None): self.x, self.y, self.order = _x, _y, _order
def calc(self, top, bottom, other_x):
l = (top * inverse_mod(bottom)) % p
x3 = (l * l - self.x - other_x) % p
return Point(x3, (l * (self.x - x3) - self.y) % p)
@dave-andersen
dave-andersen / kmeans.py
Last active September 1, 2022 11:15
k-means in Tensorflow
import tensorflow as tf
import numpy as np
import time
N=10000
K=4
MAX_ITERS = 1000
start = time.time()
@kylegibson
kylegibson / dynupdate.sh
Created October 9, 2011 18:26
Simple bash script to update a dyndns host entry
#!/bin/bash
HOST=foo.example.com
USER=
PASS=
IPADDR=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
RESULT=$(wget -q -O- "https://$USER:$PASS@members.dyndns.org/nic/update?hostname=$HOST&myip=$IPADDR&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG")
@kvnsmth
kvnsmth / example-subtree-usage.md
Last active March 5, 2023 21:58
A real world usage for git subtrees.

Let's say you have an iOS project, and you want to use some external library, like AFNetworking. How do you integrate it?

With submodules

Add the project to your repo:

git submodule add git@github.com:AFNetworking/AFNetworking.git Vendor/AFNetworking

or something to that effect.