Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Marcus Shepherd marcusshepp

🎯
Focusing
Block or report user

Report or block marcusshepp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@marcusshepp
marcusshepp / no-whitespace.sh
Last active Aug 21, 2017
git diff without white space
View no-whitespace.sh
git diff -w # ignores whitespace differences
# note that this will see no difference in "asc" and "a s c"
git diff --ignore-space-at-eol # ignores all space at the end of line
# this is most likely what you want.
# these options also work with git show
git show 2ert4d9 --ignore-all-space
git show 2ert4d9 --ignore-space-change
@marcusshepp
marcusshepp / suppress.sh
Created Aug 9, 2017
suppressing the possible error of a command
View suppress.sh
git log @{u}.. 2> /dev/null
# if git log fails, it will fail silently.
# 2> means redirecting the output of stderr.
# https://stackoverflow.com/questions/40714202/what-is-the-meaning-of-2-in-2-dev-null
@marcusshepp
marcusshepp / compare.sh
Last active Aug 9, 2017
compare local branch git log to remote branch
View compare.sh
git log @{u}..
# @{u} is a shortcut to the upstream branch that this current branch is tracking.
# .. specifies a range of commits.
# same as saying git log @{u}..HEAD
# comparing where HEAD is on this branch to where HEAD is on the remote tracked branch.s
# https://stackoverflow.com/questions/19474577/what-does-the-argument-u-mean-in-git/19474730#19474730
@marcusshepp
marcusshepp / chown.sh
Last active Nov 9, 2017
changing the permissions level of a folder
View chown.sh
sudo chown -R $USER ~/projects/kaa-api/log
View rails_queries.rb
# rails 2.3.5
p = Promotion.find(:first, :conditions => ["subdomain = ?", "foobar"])
# to find based on multiple conditions based on multiple associations
User.find(:all, :include => [:contact, :promotion], :conditions => ['contacts.email = ? and promotions.id = ?', 'marcuss@hesonline.com', 22])
# to find last record in old rails apps, rails 2
p = Promotion.find(:all, :order => "id desc", :limit => 1) # newest first
# and in ascending order
p = Promotion.find(:all, :order => "id asc", :limit => 1) # oldest first
@marcusshepp
marcusshepp / promise.js
Last active Oct 28, 2016
js ajax promise
View promise.js
function ajax(type, url){
return new Promise(function(resolve, reject){
var http_request = new XMLHttpRequest();
http_request.open(type, "http://127.0.0.1:8000/"+ url);
http_request.onload = function() {
if (http_request.status === 200){
resolve(JSON.parse(http_request.response));
} else {
reject(Error(http_request.statusText));
}
@marcusshepp
marcusshepp / is_empty.js
Last active Oct 26, 2016
is object empty
View is_empty.js
function is_empty(obj){
return Object.keys(obj).length === 0;
}
// alternative
function isEmpty(object) {
for(var i in object) {
return true;
}
return false;
@marcusshepp
marcusshepp / redo.sh
Created Oct 25, 2016
How to reset an app with an existing migration in production on postgres. Had a problem where I deployed a project with a new app with an initial migration. Then changed the migration in dev. Then redeployed with a different initial migration.
View redo.sh
psql -h 999.999.99.99 -U web_forms web_forms
web_forms=> SELECT * from django_migrations;
web_forms=> DELETE FROM django_migrations WHERE id=28;
web_forms=> DROP TABLE room_change_request_type;
# drop all tables from that app
web_forms=> \q
./manage.py migrate
@marcusshepp
marcusshepp / csrf
Created Sep 30, 2016
react django csrf middleware token component + jquery cookie function
View csrf
django-csrf-token.js
import React from 'react';
export default class DjangoCSRFToken extends React.Component {
render(){
var csrf_token = getCookie('csrftoken');
return (<input type="hidden" name="csrfmiddlewaretoken" value={ csrf_token }/>);
}
@marcusshepp
marcusshepp / webpack-dev-server.md
Last active Sep 28, 2016
setting up react and webpack dev server with hot module replacement
View webpack-dev-server.md

package.json

{
  "name": "todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "./node_modules/.bin/webpack-dev-server --inline --hot",
    "test": "echo \"Error: no test specified\" && exit 1"
You can’t perform that action at this time.