Skip to content

Instantly share code, notes, and snippets.

@marcioj
marcioj / blah.js
Created April 3, 2018 16:54
transforms wrapper.findTest("id") to findTest(wrapper, "id")
export default function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
const run = root
.find(j.CallExpression, { callee: { property: { name: "findTest" } } })
.forEach(path => {
const object = path.value.callee.object;
const args = path.value.arguments;
const prop = path.value.callee.property;
@marcioj
marcioj / script.sh
Last active December 24, 2016 12:46
Bootable flashcard
# here we use /dev/sdc1 but it can be different
# make sure the flascard is umounted
umount /dev/sdc
# format flashcard
sudo mkfs.vfat -n 'marcio-pendrive' -I /dev/sdc
# create iso
mkisofs -l -o /home/marcio/arch.iso /home/marcio/dotfiles-master/arch
# create bootable flashcard
sudo dd bs=4M if=/home/marcio/arch.iso of=/dev/sdc status=progress && sync
@marcioj
marcioj / some-initializer.rb
Created May 26, 2016 13:58
Ignore migrations with errors
class ActiveRecord::Migration
def exec_migration_with_ignore_errors(conn, direction)
begin
exec_migration_without_ignore_errors(conn, direction)
rescue => e
puts "Ignoring #{e}"
end
end
@marcioj
marcioj / fields.txt
Created May 20, 2016 19:34
Rails form helper
f.label :title => <label>Title</label>
f.text_field :title => <input type="text" />
f.text_area :body, size: "60x12" => <textarea cols="60" rows="12" ></textarea>
f.submit "Create" => <input name="commit" type="submit" />
@marcioj
marcioj / print_trace.c
Last active February 27, 2016 17:09
Print stacktraces in C
// from http://stackoverflow.com/a/4732119/1846480 and adapted from a comment to not require sudo
// It's also needed to pass the -ggdb. For instance gcc source.c -o target.o -w -ggdb
#include <sys/prctl.h>
void print_trace() {
char pid_buf[30];
sprintf(pid_buf, "%d", getpid());
char name_buf[512];
name_buf[readlink("/proc/self/exe", name_buf, 511)]=0;
@marcioj
marcioj / index.js
Created December 24, 2015 19:08
Print AST to code in Babel 5.x
import generate from 'babel-core/lib/generation';
let file;
function print(ast) {
// duck type NodePath
if (ast.node) {
ast = ast.node;
}
console.log(generate(ast, file.opts, file.code).code);
@marcioj
marcioj / options.sh
Last active December 1, 2015 15:22
Parsing CLI options in bash
# taken from http://www.unix.com/302182212-post4.html
while true
do
case $# in 0) break ;; esac
case $1 in
-d|--dir) shift; dir=$1; shift ;;
-u|--user) shift; user=$1; shift ;;
-a|--all) shift; all=true ;;
-|--) shift; break;;
@marcioj
marcioj / user.js
Created April 3, 2015 15:59
DS.Model using javascript decorators
import DS from 'ember-data';
function model(clazz) {
var propertyNames = Object.getOwnPropertyNames(clazz.prototype);
var hash = {}
propertyNames.forEach( (prop) => {
if (prop !== "constructor") {
hash[prop] = Object.getOwnPropertyDescriptor(clazz.prototype, prop).value;
}
})
App.IndexRoute = Ember.Route.extend({
viewName: "foo"
});
App.FooView = Ember.View.extend({
didInsertElement: function() {
console.log("FooView")
}
});
@marcioj
marcioj / app.js
Last active August 29, 2015 14:15
App = Ember.Application.create();
var html = $("#myTemplate").remove().html();
var template = Ember.Handlebars.compile(html);
var model = "Click here";
var controller = { model: model };
var view = Ember.View.create({
template: template,