Skip to content

Instantly share code, notes, and snippets.

View markandrewj's full-sized avatar

Mark Jackson markandrewj

  • Canada
View GitHub Profile
// Universal mongodb reduce function for complex objects
//
// Example:
//
// emit({ total_views: 3, page_type: {home: 1, product: 2}, site_id: [1] })
// emit({total_views: 5, page_type: {home: 1, collection: 4}, site_id: [2]})
//
// -> reduce
//
// { total_views: 8, page_type: { home: 2, product: 2, collection: 4 }, site_id: [1,2] }
<?php
/**
* The code below shows example usage of the SecureHash class for
* encrypting a password. In terms of additional usage, you should
* store the resulting encrypted password in addition to the salt
* in your db.
*/
// load the class
$secure = new SecureHash();
angular.module('itemServices', ['ngResource'])
.factory('Item', ['$resource',
function ($resource) {
return $resource('items/:id',
{id: '@id'},
{
query: {
isArray: true,
method: 'GET',
params: {},
@markandrewj
markandrewj / 0_reuse_code.js
Created August 1, 2014 03:29
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@markandrewj
markandrewj / curl-json.php
Last active August 29, 2015 14:05
JSON Curl function for PHP
<?php
function curl_json($base_url='',$query='',$json=true){
//set the url to use
$target_url = 'http://www.mydomain.com/json_script.json';
$url == ($base_url='' ? $target_url : $base_url) ;
//set default json
$default_json ='[you json string here]';
@markandrewj
markandrewj / nice-git-tree
Last active August 29, 2015 14:05
Nice Git Tree
git config --global alias.tree 'log --graph --full-history --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cblue%d %Creset %s %C(bold)(%an)%Creset"'
// npm install bcrypt
var bcrypt = require('bcrypt');
var password = process.argv[2];
bcrypt.genSalt(function(err, salt) {
if (err) {
console.log(err);
}
console.log('salt: ' + salt + ' (length: ' + salt.length + ')');
@markandrewj
markandrewj / bash_bug_test
Created October 14, 2014 12:25
Check if bash bug has been patched
env 'VAR=() { :;}; echo Bash is vulnerable!' 'FUNCTION()=() { :;}; echo Bash is vulnerable!' bash -c "echo Bash Test"
from scapy.all import *
print sr1(IP(dst="4.2.2.1")/ICMP()).summary()