Skip to content

Instantly share code, notes, and snippets.

var wrapLog = function (callback, name) {
//var args = callback.apply(null,arguments);
//console.log(arguments);
//console.log(args);
//console.log(arguments[0]);
//console.log(arguments);
return function() {
//console.log(arguments);
//console.log(callback.apply(null,arguments));
//var arg2 = 1, arg1 = 2;
@wichopy
wichopy / Network_Drive_File_Extraction.py
Created February 10, 2017 14:47
scan network folders and populate a csv file with file names, date modified and folder locations.
import os
import csv
import datetime
import timeit
import pandas as pd
import pickle
flcount = 0
addcount = 0
lastadded = 0
@wichopy
wichopy / image_resize.py
Last active February 10, 2017 22:15
Scan a folder and reduce and jpgs larger then 3 MB to 1024x786 resolution.
from PIL import Image
from resizeimage import resizeimage
import os
dir = 'C:\Users\chouw\Documents\pictures'
for dirname,subdirlist,flist in os.walk(dir):
for fname in flist:
if fname.lower().endswith('.jpg'):
if os.stat(dir+"\\"+fname).st_size > 3000:
print "resize {}".format(fname),
with open(dir+"\\"+fname, 'r+b') as f:
import pandas as pd
import os
import datetime
import numpy as np
#This will be the directory with all the sheets to combine.
questdir = 'C:\Users\chouw\Desktop\Load3'
#chunk of code to verify file count matches.
files = []
@wichopy
wichopy / findandmoifyone.js
Created February 25, 2017 15:05
Find and modify one document in Mongo DB
db.tweets.findAndModify({query: {"likes" : null},update:{$set: {"likes": []}},new: true, upsert: true })
@wichopy
wichopy / findandupdatemany.js
Created February 25, 2017 15:10
Mongo command to find and update multiple documents..
db.tweets.updateMany({ {"likes" : null},{$set: {"likes": []}} })
@wichopy
wichopy / railsdb.rb
Created March 17, 2017 16:14
Create new model, migration and manually insert data.
command to insert:
r = Rating.create :user_id => 1, :product_id => 1, :description => 'I dont like this shirt', :rating => 2
To run migration:
bin/rake db:migrate
To create anew migration for adding in reference columns :
bin/rails generate migration AddUserAndProductToRatings user:references product:references
Create a new model/migration
@wichopy
wichopy / isolateKeys.js
Last active January 9, 2018 21:08
Immutable removal of keys from a javascript object using ES6 deconstructing.
//Avoid annoying immutability bugs by using this nice ES6 deconstructing trick to keep your object immutable.
// example obj
const someObj = {
want: 'this',
need: 'that',
dont: 'wantthis',
forget: 'this'
};
@wichopy
wichopy / filterString.js
Created February 3, 2018 03:01
Filter out text strings using regex of a URL.
// assuming env var
// BASE_URL=www.mydomain.com
removebaseURL = (fullURL) => { // pass in (www.mydomain.com/kittens)
// Allow api calls to handle just the end point (/kittens) or the full URL (www.mydomain.com/kittens)
// by filtering out the base URL if the route contains it.
const reg = new RegExp(process.env.BASE_URL, 'gi');
const match = fullURL.match(r eg)
let endpoint
if (match) {
endpoint = fullURL.split(reg)[1]
@wichopy
wichopy / redeploy.sh
Created May 1, 2018 00:53
Redeploy server war and restart postgres docker container locally.
#!/bin/bash
echo "Stop tomcat";
/Library/Tomcat/bin/shutdown.sh;
echo "Restart postgres container";
#Assuming you have docker, with a postgres container running called local-postgres. The postgres container can be renamed in the docker run command.
docker stop local-postgres;
docker rm local-postgres;
docker run --name local-postgres -e POSTGRES_USER=user -e POSTGRES_DB=db -d -p 5432:5432 postgres;