Skip to content

Instantly share code, notes, and snippets.

View sle-c's full-sized avatar
🏠
Working from home

Si Le sle-c

🏠
Working from home
View GitHub Profile
@sle-c
sle-c / Dockerfile
Created July 15, 2016 02:57
Dockerfile for dropbox babl module
FROM python:2.7.12-alpine
RUN wget -O- "http://s3.amazonaws.com/babl/babl-server_linux_amd64.gz" | gunzip > /bin/babl-server && chmod +x /bin/babl-server
ADD app /data/
RUN ln -s /data/app /bin/app
RUN chmod +x /bin/app
WORKDIR /data
RUN pip install -U pip
RUN pip install dropbox
CMD ["babl-server"]
@sle-c
sle-c / app.py
Last active July 18, 2016 03:47
dropbox babl module dependencies
#!/usr/local/bin/python
import dropbox
import os
import sys
@sle-c
sle-c / main.py
Created July 18, 2016 04:27
Babl module full main program
def main():
tempFile = ''.join(sys.stdin.readlines())
try:
token = os.environ["TOKEN"]
dest_path = os.environ["FILE"]
except KeyError as err:
print "One or more environment variable are missing, %s" % err
return
@sle-c
sle-c / dropbox-upload.py
Created July 18, 2016 04:29
Babl module dropbox upload method
def upload(dbx, data, path, overwrite=False):
"""Upload a file.
Return the request response, or None in case of error.
"""
mode = (dropbox.files.WriteMode.overwrite
if overwrite
else dropbox.files.WriteMode.add)
try:
res = dbx.files_upload(data, path, mode)
@sle-c
sle-c / dropbox-sharelink.py
Created July 18, 2016 04:30
babl module dropbox get share link
@sle-c
sle-c / rails_uglifier_debug.rb
Created August 11, 2017 17:19
Debugging rails asset pipeline js precompile errors with uglifier
# runs rails console and copy + paste this snippet in to see the offending file
JS_PATH = "app/assets/javascripts/**/*.js";
Dir[JS_PATH].each do |file_name|
puts "\n#{file_name}"
puts Uglifier.compile(File.read(file_name))
end
@sle-c
sle-c / subscribe_to_activities.js
Created September 6, 2018 18:29
subscribe to firebase activities
db.collection("activities").where("userID", "==", currentUserID)
.onSnapshot(function(snapshot) {
snapshot.docChanges().forEach(function(change) {
doSomething(change.doc.data());
});
});
@sle-c
sle-c / subscribe_to_activities_with_counter.js
Created September 6, 2018 18:32
Subscribe to firebase activities with counter
function handleActivitySubscription(snapshot) {
snapshot.docChanges().forEach(function(change) {
doSomething(change.doc.data());
});
}
const handleActivitySubscriptionWithCounter =
createFnCounter(handleActivitySubscription, 1);
db.collection("activities").where("userID", "==", currentUserID)
@sle-c
sle-c / create_random_key.go
Last active April 1, 2019 00:48
Create random key string
import (
"crypto/rand"
)
func NewRandomKey() []byte {
key := make([]byte, 32)
if _, err := rand.Read(key); err != nil {
// really, what are you gonna do if randomness failed?
panic(err)
}
@sle-c
sle-c / create_apps_table.sql
Last active April 1, 2019 02:16
JWT Auth with Golang
CREATE TABLE apps (
id SERIAL PRIMARY KEY,
name character varying,
public_key character varying,
encrypted_secret_key character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
-- enhance query performance and enforce uniqueness
CREATE UNIQUE INDEX apps_public_key ON apps(public_key text_ops);