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 / checkbox_extract_script.bas
Created March 19, 2017 15:28
Script to extract data from excel checkboxes.
Sub CheckboxLoop()
'Using this as a start:
'PURPOSE: Loop through each Form Control Checkbox on the ActiveSheet
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim cb As Shape
Dim i As Integer
@wichopy
wichopy / Jenkinsfile.groovy
Created November 20, 2017 00:53 — forked from Faheetah/Jenkinsfile.groovy
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'No quotes in single backticks'
sh 'echo $BUILD_NUMBER'
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"'
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"'
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"'
echo 'Using three backslashes still results in preserving the single quotes'
@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'
};