Skip to content

Instantly share code, notes, and snippets.

@samuelsmal
samuelsmal / edn-to-csv.clj
Created April 6, 2016 08:20
Clojure script to extract some fields from a edn-file and store it as a CSV file
#!/usr/bin/env boot
(require '[clojure.java.io :as io])
(require '[clojure.edn :as edn])
(def fname "/path/to/clojure-edn.clj")
(def ofname "/path/to/out.csv")
;; out-format:
;; "keykeykey", "valvalval"
@samuelsmal
samuelsmal / sam-on-enter.directive.js
Created January 14, 2016 10:21
onEnter angular directive
/* global angular: false */
(function () {
'use strict'
angular
.module('sam.utils')
.directive('onEnter', onEnter)
function onEnter () {
@samuelsmal
samuelsmal / partial.directive.js
Last active January 13, 2016 16:02
Angular partial directive (Rails partial equivalent)
/* global angular: false */
;(function () {
'use strict'
/**
* sam-partial directive
*
* This is simple *partial* directive. It functions the same as `ng-include`
* but instead of nesting it replaces the element.
@samuelsmal
samuelsmal / api-version-comparator.js
Created October 12, 2015 09:00
Javascript API Version comparator function
/**
* Compares two given API version strings in base 10. Only numbers separated by a dot (".") are supported.
* It compares lhs < rhs and returns the default UNIX comparison identifier:
*
* if lhs < rhs
* return -1
* else if lhs > rhs
* return 1
* else
* return 0
@samuelsmal
samuelsmal / goldenratio.variables.scss
Created September 22, 2015 12:03
A list of golden ration variables. Based upon gld.chadlindemann.com
$golden: 1.618;
$base: 100%;
$gld10: $base / $golden;
$gld9: $base - $gld10;
$gld8: $gld9 / $golden;
$gld7: $gld9 - $gld8;
$gld6: $gld7 / $golden;
$gld5: $gld7 - $gld6;
$gld4: $gld5 / $golden;
$gld3: $gld5 - $gld4;
@samuelsmal
samuelsmal / runge_kutta.nb
Last active August 29, 2015 14:18
Mathematica Runge-Kutta
(* One step Runge-Kutta *)
(* fn : Definition of the function *)
(* init : List of initial values, dimensions have to agree with the input of fn *)
(* step : Step size for the numerical simulation *)
(* Usage: *)
(* One step: *)
(* RungeKutta[{#[[2]], #[[1]]^2 - 2#[[2]]}&,{.1, -.5}, .1] *)
(* Multiple steps: *)
(* NestList[RungeKutta[{#[[2]], #[[1]]^2 - 2#[[2]]}&, #, 0.1]& , {.1, -.5}, 5] *)
@samuelsmal
samuelsmal / pomodoro.sh
Created December 3, 2014 14:40
command line pomodoro timer
#!/bin/bash
while true; do
sleep 1500 && notify-send "break"; sleep 300 && notify-send "back to work";
done
@samuelsmal
samuelsmal / create-git-alias.md
Created November 6, 2014 01:22
List of helpful command line commands

This answer builds upon the [answer][1] by [johnny][2]. I got it from stackoverflow user A-B-B.

It applies if you're not using [git-alias][3] from [git-extras][4].

On Linux, run once:

git config --global alias.alias "! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /"

This will create a permanent git alias named alias which gets stored in your ~/.gitconfig file. Using it will list all of your git aliases, in nearly the same format as they are in the ~/.gitconfig file. To use it, type:

@samuelsmal
samuelsmal / code
Created November 4, 2014 22:26
Printing a vector to stdout
#include <vector
#include <algorithm> // for copy, for_each
#include <iterator> // for ostream_iterator
std::copy(vector.cbegin(), vector.cend(), std::ostream_iterator<vector_element_type>(std::cout, " "));
std::for_each(vec.cbegin(), vec.cend(), [] (const vector_element_type c) {std::cout << c << " ";});
@samuelsmal
samuelsmal / Stats
Created October 6, 2014 11:24
Check if a file exists
Method exists_test0 (ifstream): **0.485s**
Method exists_test1 (FILE fopen): **0.302s**
Method exists_test2 (posix access()): **0.202s**
Method exists_test3 (posix stat()): **0.134s**