Skip to content

Instantly share code, notes, and snippets.

@lucas-clemente
lucas-clemente / gist:9623826
Created March 18, 2014 16:34
convert sublime snippets to atom
require "json"
json = JSON.parse(IO.read('snippets.json'))
json.each do |s|
name = s["contents"]
prefix = s["trigger"]
body = s["contents"]
puts name.to_json
puts " 'prefix': #{prefix.to_json}"
(* ::Package:: *)
BeginPackage["SimpleAssume`"]
Unprotect @@ Names["SimpleAssume`*"];
ClearAll @@ Names["SimpleAssume`*"];
$Assumptions={}
AssumeReal::usage = "assume variables to be real";
AssumeRealPositive::usage = "assume variables to be real and positive";
@lucas-clemente
lucas-clemente / cron.rb
Last active August 29, 2015 14:02
Proof of concept for calculating cron job times
#!/usr/bin/env ruby
# Calculate the next match for cron conditions (secs).
# Numbers > 60 mean the match is in the next minute.
#
# Arbitrary conditions:
# just take the minimum of all the individual ones.
# 60 secs / min
# Description:
# YO
#
# Commands:
# hubot yo <name> - YO
module.exports = (robot) ->
robot.respond /YO (\w+)$/i, (msg) ->
token = process.env.HUBOT_YO_TOKEN
data = "api_token=#{token}&username=#{msg.match[1]}"
### Keybase proof
I hereby claim:
* I am lucas-clemente on github.
* I am lclemente (https://keybase.io/lclemente) on keybase.
* I have a public key whose fingerprint is E2A4 476D E63B 0B27 B357 0F26 4273 9281 0E47 693A
To claim this, I am signing this object:
@lucas-clemente
lucas-clemente / gist:1835987
Created February 15, 2012 14:12
Latex wrapper for bibtex
#!/usr/bin/env ruby -w
# Save to pdflatex to ~/bin/pdflatex
if ARGV.length == 0
puts "Usage: texify <file.tex> <tex options>"
exit 1
end
file = ARGV.select{|v| v =~ /.*\.tex/}[0]
#!/usr/bin/env ruby -wKU
require 'rainbow'
def exec_cmd(cmd, ignore_fail = false)
puts cmd.bright
if !system(cmd, :out => File.open(File::NULL, 'w'))
if ignore_fail
return 1
else
@lucas-clemente
lucas-clemente / rvm.fish
Created June 11, 2012 08:29
Fix for .config/fish/functions/rvm.fish
function rvm -d 'Ruby enVironment Manager'
# run RVM and capture the resulting environment
set -l env_file (mktemp -t rvm.fish.XXXXXXXXXX)
bash -c 'source ~/.rvm/scripts/rvm; rvm "$@"; status=$?; env > "$0"; exit $status' $env_file $argv
# apply rvm_* and *PATH variables from the captured environment
and eval (grep '^rvm\|^[^=]*PATH' $env_file | sed '/^[^=]*PATH/y/:/ /; s/^/set -xg /; s/=/ /; s/$/ ;/; s/(//; s/)//')
# clean up
rm -f $env_file
@lucas-clemente
lucas-clemente / validate.rb
Created July 7, 2012 17:20
Validate all rows in a rails database
Dir['app/models/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize }.map { |c| {c.name => c.all.select {|f| f.invalid?}.map {|f| f.errors}}}
@lucas-clemente
lucas-clemente / gist:3217147
Created July 31, 2012 13:45
Mathematica assumptions helper
$Assumptions = {# \[Element] Reals, # > 0} & /@ {m, k, T} // Flatten;