Skip to content

Instantly share code, notes, and snippets.

View jobwat's full-sized avatar

Jo Boiteau jobwat

  • Servian
  • Sydney
View GitHub Profile
@jobwat
jobwat / helper.js
Created June 7, 2011 00:13
Dynamic resize element text font-size to fit parent element width
Helpers.updateResizeInput = function(el, text){
if(el[0].localName == "input"){ // inputs are a pain (width auto is wrong & innerHTML <> value)
if(text==undefined) text = el[0].value;
el.parent().prepend('<span id="test" />');
var theSpan = $('span#test', el.parent());
theSpan.value = text;
Helpers.updateResizeInput(theSpan, text);
el.css('font-size', theSpan.css('font-size'));
el.css('margin-top', theSpan.css('margin-top'));
el[0].value = text;
#!/bin/bash
# inspired from: https://gist.github.com/vitobotta/2783513
threshold=300 # after 5min of uptime, a job is considered 'stuck', to kill
logfile=log/dead_workers_killed.log
function ps_etime_to_seconds() # cheers user000001 - http://stackoverflow.com/questions/14652445/parse-ps-etime-output-into-seconds#14653443
{
echo $1 | awk -F $':' -f <(cat - <<-'EOF'
Dir.chdir "/home/vagrant/app"
logs = `git log --pretty 1.2.0..1.2.1 | grep -E "(T ?M[-_ ]?[0-9]+|T ?T[-_ ]?[0-9]+)"`
labels = logs.each_line.map do |line|
line.scan(/T ?[TM][-_ ]?[0-9]+/i).map do |s|
s.upcase.gsub(/T ?([TM])[^\d]?(\d+)/, 'T\1-\2')
end
end
final_list = labels.sort.uniq{|s|s.first}
#!/bin/bash
exit_code=0
tests='
echo -n "MemCache service listening... "; netstat -l | grep "memcache.*LISTEN" > /dev/null 2>&1
echo -n "App returning Set-Cookie: XRSF-TOKEN header... "; curl -I localhost 2>/dev/null | grep "Set-Cookie: XSRF-TOKEN" > /dev/null
echo -n "App /status return 200... "; curl --connect-timeout 1 localhost/status > /dev/null 2>&1
'
IFS=$'\n'
@jobwat
jobwat / CONSTANT.rb
Created May 2, 2014 07:03
Constant lookup limitation in Ruby
class Foo
def self.showConstant
puts CONSTANT
end
end
class SubFoo < Foo
CONSTANT='SubFoo string'
end
SubFoo.showConstant
@jobwat
jobwat / csv_from_sql_rails.rb
Created May 16, 2014 01:52
SQL to CSV with Rails
sql='select event_type as code, country, state, location, name from tracks group by code, country, state, location, name order by code, country, state, location, name;'
pg_res = ActiveRecord::Base.connection.execute(sql)
csv_file = CSV.generate do |csv|
csv << %w{code country state location name}
pg_res.values.each { |line| csv << line }
end
File.write('tmp/tracks_export.csv', csv_file)
@jobwat
jobwat / travis-ci.logging.txt
Created May 20, 2014 06:25
troubleshooting Travis-CI.org access
# first, log in
bundle exec travis login
# wanna see the token ?
bundle exec travis token
# check that this token tokens
curl -H "Authorization: token $(bundle exec travis token)" https://api.travis-ci.org/users/
# Works ?????
@jobwat
jobwat / kill9
Last active September 10, 2021 06:13
My kill9 script (old)
#!/bin/bash
# ---------------------------------------------------
# Original script name: kill9
#
# Object: Kill the matching given name processes
# ---------------------------------------------------
if [ -z $1 ]; then
echo "Error: missing search arguments... exiting"
@jobwat
jobwat / build.gradle
Last active December 13, 2021 07:54 — forked from twocity/build.gradle
custom versionName with versionCode + timestamp, in release apk filename
android {
....
defaultConfig {
...
versionCode 3
versionName versionCode + "-" + getTimestamp()
}
...
...
applicationVariants.all { variant ->
@jobwat
jobwat / shift_datetime.sh
Created April 8, 2015 05:42
Shift the datetime of files according to the sample gap
ref_file=GOPR3440.MP4
new_time_for_that_file=0327160015 #date's format: 27th March 2015, 16:00
ref_file_timestamp=`stat -f %B -t %s "$ref_file"`
new_time_timestamp=`date -j $new_time_for_that_file +%s`
time_diff=$[$new_time_timestamp - $ref_file_timestamp]
for f in *; do
old=$(stat -f %B -t %s "$f")
new=$(date -r $(($old + $time_diff)) '+%m/%d/%Y %H:%M:%S')