Skip to content

Instantly share code, notes, and snippets.

View sourcec0de's full-sized avatar
:octocat:
Focusing

James R Qualls sourcec0de

:octocat:
Focusing
View GitHub Profile
@sourcec0de
sourcec0de / resize.js
Created March 17, 2015 18:10
I wrote this snippet to resize a folder full of high res images.
'use strict';
var gm = require('gm');
var glob = require('glob');
var async = require('async');
var uuid = require('node-uuid');
var join = require('path').join;
@sourcec0de
sourcec0de / slugify.js
Created December 10, 2014 20:06
Slugify strings in javascript
var r1 = /(?!\n)\W/ig;
var r2 = /\s{1,}/ig;
function slugify(str){
return String(str).replace(r1, ' ').replace(r2, '-').toLowerCase().trim();
}
def smallest(x, y, z):
"""
put a set of numbers in an array
sort them least to greatest
return the first element in the array to get the smallest
"""
nums = [x, y, z]
nums.sort()
return nums[0]
@sourcec0de
sourcec0de / init-dl-js.md
Last active August 30, 2018 15:12
Initiating downloads in javascript

Downloads in javascript

Method 1

Use this method when viewing images or textual data. It allows you to open it in a seperate window. This will cause a popup blocker to react.

window.open(url,'_blank');
@sourcec0de
sourcec0de / CSV.js
Last active August 29, 2015 14:07
Basic CSV writer in javascript
function CSV(){
this.headers = [];
this.headersWriten = false;
this.delimiter = ',';
this.write = print || console.log;
this.print = function (row){
if (this.headersWriten === false) {
this.headers = Object.keys(row);
@sourcec0de
sourcec0de / node_nginx.md
Last active January 6, 2016 16:53
Node.JS and Nginx config ubuntu

Serve Node.js with NGINX on Ubuntu

Installing NGINX

Install the dependencies

apt-get update
apt-get install python-software-properties software-properties-common libssl-dev build-essential

Keybase proof

I hereby claim:

  • I am sourcec0de on github.
  • I am sourcec0de (https://keybase.io/sourcec0de) on keybase.
  • I have a public key whose fingerprint is 89E5 4811 A862 41DD 3CE6 5CD1 6A89 304A F032 6AAB

To claim this, I am signing this object:

@sourcec0de
sourcec0de / domain
Last active August 29, 2015 14:07
Routing subdomains in express.js
# set your nginx config to route wild cards
server_name *.domain.com;
# if you dont want to use nginx you can test by modifying you host file
sudo nano -w /private/etc/hosts
# add line
127.0.0.1 testing.expresshost.com
# Then open http://testing.expresshost.com:3080
# and you should see the subdomain in the response
type Whatever struct {
someField int
}
func (w Whatever) MarshalJSON() ([]byte, error) {
return json.Marshal(struct{
SomeField int `json:"some_field"`
}{
SomeField: w.someField,
})
@sourcec0de
sourcec0de / nginx.conf
Last active August 29, 2015 14:06 — forked from plentz/nginx.conf
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048