Skip to content

Instantly share code, notes, and snippets.

View fodra's full-sized avatar
🎯
Focusing

Andrew Artajos fodra

🎯
Focusing
  • Australia
View GitHub Profile
@fodra
fodra / DjangoCheatSheet.md
Last active March 26, 2017 22:39
A bunch of usually used django commands.

Create

Start a new project

$ django-admin startproject moneymakingsite

Create a new django application

$ python manage.py startapp merchandise

@fodra
fodra / FodraGitCheatSheet.md
Last active March 30, 2017 03:27
There are myriad of git cheatsheets out there. This one is different. This is my git cheatsheet.

Delete a crappy remote branch

The : (colon) makes all the difference. Quite dumb really.

$ git push origin :feature/crap_feature

Unstage a file

I accidentally staged a file for commit -- but I don't want to.

@fodra
fodra / FodraSublimeTextCheatSheet.md
Last active April 5, 2017 05:03
Stuff I usually forget when using Sublime Text 3

Folder Locations

Snippets and Settings

  • Go to Preferences > Browse Packages...
  • This will open up an Explorer / Finder window depending on what OS you use.
  • Under the User folder, there lives your user settings and your snippets.
@fodra
fodra / FodraLinuxCheatSheet.md
Last active June 19, 2018 07:06
These are a bunch of Linux commands I Google search all the time. ALL EFFIN' TIME.

Linux Commands

Redirect stderr and stdout to a file

  1. I always always need to do this.

$ ./a.out 2>&1 | tee output

  1. Find command very basic
@fodra
fodra / get_attr.py
Created April 21, 2017 00:42
Found this in django-zebra a utility to get the attribute if it exists.
def _get_attr_value(instance, attr, default=None):
"""
Simple helper to get the value of an instance's attribute if it exists.
If the instance attribute is callable it will be called and the result will
be returned.
Optionally accepts a default value to return if the attribute is missing.
Defaults to `None`
@fodra
fodra / scopes.txt
Created June 7, 2017 01:50 — forked from iambibhas/scopes.txt
Sublime Text 2: Snippet scopes
Here is a list of scopes to use in Sublime Text 2 snippets -
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
CoffeeScript: source.coffee
@fodra
fodra / promise-chaining.js
Created August 24, 2017 03:50
These are two examples on how to chain promises that need to be executed one after the other.
const readSession = function(portHandle, sectors) {
// this holds the result
let result = [];
// this is the entry point of the recursive func
let _readAll = function(sectorsToRead) {
// when there's no more sectore to read
// we stop and return the result
if (sectorsToRead.length === 0) {
return result;
}
+ // Write on keyup event of keyword input element
+ $("#search").keyup(function(){
+ _this = this;
+ // Show only matching TR, hide rest of them
+ $.each($("#teamTable tbody tr"), function() {
+ if($(this).text().toLowerCase().indexOf($(_this).val().toLowerCase()) === -1)
+ $(this).hide();
+ else
+ $(this).show();
+ });
@fodra
fodra / sudo_command.exp
Last active September 27, 2017 04:02
This will execute a command that requires root access. Usage ./sudo_command.exp <password> <command>
#!/usr/bin/expect
# argv 0 is password
# argv 1 is command e.g. kextload -b info.stichling.USBCDCACMControl
# get the password from the commandline
set password [lindex $argv 0]
# get the command from the commandline
set command "sudo [lindex $argv 1]"
@fodra
fodra / using-function-prototype-apply.md
Created November 15, 2017 05:03
Using Function.prototype.apply() a practical example.

Issue

Being used to Python, I am looking for a min function in Javascript that would accept a list and returns the minimum value in the list.

Python

This is as easy as minimum = min([4, 4, 3, 2, 1])

Javascript