Skip to content

Instantly share code, notes, and snippets.

@ruthenium
ruthenium / hide.full.js
Last active August 8, 2018 14:46
Hide all posts without media at the Invision forums
(function(){
function addLink(target) {
var div = document.createElement('div');
var a = document.createElement('a');
a.setAttribute('href', '#');
a.textContent = 'No media in post';
a.addEventListener('click', function(e){
if (target.style.display == "none") {
target.removeAttribute('style');
} else {
@ruthenium
ruthenium / import_string.py
Created January 10, 2018 23:02
import_string from django
# -*- coding: utf8 -*-
# this is from django.utils.module_loading
from importlib import import_module
def import_string(dotted_path):
"""
Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImportError if the import failed.
"""
@ruthenium
ruthenium / polarToCartesian.js
Created February 24, 2017 17:19 — forked from Raisi/polarToCartesian.js
Transform Polar to Cartsian Coordinats
/**
* Coordinates Transformations
*
* http://stackoverflow.com/questions/5736398/how-to-calculate-the-svg-path-for-an-arc-of-a-circle
*
* @param centerX
* @param centerY
* @param radius
* @param angleInDegrees
* @returns {string}
@ruthenium
ruthenium / cartesianToPolar.js
Created February 24, 2017 17:19 — forked from cevherkarakoc/cartesianToPolar.js
Converting cartesian coordinates to polar coordinates
function cartesianToPolar(x,y){
return {
radius: Math.sqrt( Math.pow(x, 2) + Math.pow(y, 2) ),
alpha: Math.atan2(y, x)
}
}
@ruthenium
ruthenium / polarToCartesian.js
Created February 24, 2017 17:19 — forked from cevherkarakoc/polarToCartesian.js
Converting polar coordinates to cartesian coordinates
function polarToCartesian(radius,radian){
return {
x:radius*Math.cos(radian),
y:radius*Math.sin(radian)
}
}
@ruthenium
ruthenium / gist:7e8620b6974f151d52809c0b2075b59f
Created February 24, 2017 17:18 — forked from keiya/gist:1190856
convert polar - cartesian
// thx tomy! http://www5.airnet.ne.jp/tomy/cpro/sslib12.htm
function cartesian2polar(x,y,z) {
var obj = new Object;
obj.r = Math.sqrt( x*x + y*y + z*z );
if (x != 0.0)
obj.phi = Math.atan2( y, x );
else {
if (y < 0.0)
@ruthenium
ruthenium / Hopfield-mini.hs
Created September 5, 2016 20:52 — forked from nh2/Hopfield-mini.hs
Hopfield networks - minimal Haskell implementation
import Data.Vector ((!))
import qualified Data.Vector as V
import Data.Vector.Generic.Mutable (write)
step ws state = case updatable of [] -> state
(i,_):_ -> V.modify (\v -> write v i (o i)) state
where
n = V.length state
w i j = ws ! i ! j
@ruthenium
ruthenium / find and xargs
Created August 28, 2016 22:46 — forked from denitram/find and xargs
find & xargs
# Find tutorial;
# http://www.grymoire.com/Unix/Find.html
# find files modified less than 5 days ago
$ find . -type f -mtime -5 -print | xargs ls -l
# find files (with spaces in name) modified less than 5 days ago
$ find . -type f -mtime -5 -print0 | xargs -0 ls -l
# find & remove directories older than 200 days
@ruthenium
ruthenium / gist:4bbb2610606b8678830c5d4aa776b5f7
Last active August 28, 2016 15:11 — forked from ninux/gist:5713741
Merge PDFs with Ghostscript
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
# found at https://bbs.archlinux.org/viewtopic.php?id=65036
# some automation (merge all in current directory):
find . -type f -print0 | xargs -0 gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="/path/finished.pdf"
@ruthenium
ruthenium / gist:64c0df5234ac0425215f19d88167cff6
Created August 16, 2016 15:26 — forked from StephenPunwasi/gist:95cd8d77b0a1a956b07cda99ef098af6
Exclude OS X .DS_Store and Git files when zipping.
zip -r [filename.zip] [foldername] -x "*.DS_Store" -x *.git*