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 / config-react.md
Last active April 24, 2019 04:44
Create react app with webpack 4

Webpack config

Init project

mkdir project-folder
cd project-folder
npm init
@sle-c
sle-c / create_fn_counter.js
Last active June 10, 2020 00:13
Wrap a function and count how many time it's being invoked
function createFnCounter(fn, invokeBeforeExecution) {
let count = 0;
return (snapshot) => {
count++;
if (count <= invokeBeforeExecution) {
return null;
}
return fn(snapshot, count);
@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)