Skip to content

Instantly share code, notes, and snippets.

View tokenvolt's full-sized avatar

Alex Khrustalev tokenvolt

View GitHub Profile
@tokenvolt
tokenvolt / default_image.rb
Created July 26, 2013 23:05
Default images for carrierwave using placeholder.it
class DefaultImage
def initialize(width, height)
@width = width
@height = height
end
def create(options={})
name = options[:name] || "image_#{Time.now.to_i}"
default_format = 'png'
@tokenvolt
tokenvolt / Curl json post request
Last active December 21, 2015 16:49
Post a json request with data using curl.
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d jsondata http://localhost:3000/api/path
@tokenvolt
tokenvolt / simple_form_bootstrap3.rb
Last active November 2, 2023 11:55
Bootstrap 3 simple form initializer
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
RangeInput
StringInput
TextInput
@tokenvolt
tokenvolt / vanillajs-ajax.js
Last active December 6, 2016 19:29
VanillaJS ajax wrapper.
// http://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery/18078705#18078705
var ajax = {};
ajax.xhr = function() {
try {
return new ActiveXObject('Msxml2.XMLHTTP')
} catch (e1) {
try {
return new ActiveXObject('Microsoft.XMLHTTP')
} catch (e2) {
@tokenvolt
tokenvolt / sublime.json
Created November 1, 2013 12:18
Sublime settings
Sublime User settings
{
"font_size": 11,
"ignored_packages":
[
"Vintage"
],
"tab_size": 2,
"translate_tabs_to_spaces": true,
@tokenvolt
tokenvolt / 0_reuse_code.js
Created November 3, 2013 12:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tokenvolt
tokenvolt / gist:8850823
Created February 6, 2014 19:20
Sidekiq logger
Sidekiq.logger.formatter = proc do |severity, timestamp, context, message|
case severity
when 'INFO'
severity = severity.green
when 'ERROR'
severity = severity.red
else 'WARN'
severity = severity.yellow
end
// backup
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
// restore
mysql -u root -p[root_password] [database_name] < dumpfilename.sql
var data;
data = {
user: {
email_address: "joe@bloggs.com",
provider: "linkedin",
uid: "1234567",
info: {
nickname: "jbloggs",
name: "Joe Bloggs",
@tokenvolt
tokenvolt / postgres_drop_connections
Created July 16, 2014 15:23
Drop postgres connections for specific DB
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'TARGET_DB' AND pid <> pg_backend_pid();