Skip to content

Instantly share code, notes, and snippets.

View KimTrijnh's full-sized avatar
🎯
Focusing

Huong111 KimTrijnh

🎯
Focusing
View GitHub Profile
@KimTrijnh
KimTrijnh / bind_socket.py
Created September 19, 2021 05:05 — forked from tuxfight3r/bind_socket.py
python tcp socket client / server examples
#!/usr/bin/python
import socket #for sockets
import sys #for exit
try:
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
print 'Failed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1]
set ignorecase
set smartcase
set scrolloff=3 " 3 lines above/below cursor when scrolling
" Emulated Plugins
set surround
" Copy to system clipboard as well
set clipboard+=unnamed
@KimTrijnh
KimTrijnh / git_jira_github_pull_request.sh
Created July 16, 2021 06:41 — forked from StevenACoffman/git_jira_github_pull_request.sh
Create Github pull request from JIRA and git
#!/bin/bash
function safe_curl() {
# call this with a url argument, e.g.
# safecurl.sh "http://eureka.test.cirrostratus.org:8080/eureka/v2/apps/"
# separating the (verbose) curl options into an array for readability
hash curl 2>/dev/null || { echo >&2 "I require curl but it's not installed. Aborting."; exit 1; }
hash jq 2>/dev/null || { echo >&2 "I require jq but it's not installed. Aborting."; exit 1; }
hash sed 2>/dev/null || { echo >&2 "I require sed but it's not installed. Aborting."; exit 1; }
@KimTrijnh
KimTrijnh / uniq.rb
Created July 6, 2020 05:21 — forked from mahemoff/uniq.rb
Ensure Sidekiq jobs are unique (if the queue contains several jobs with same class and args, this will delete all but one of them)
def self.uniq! queue_name
seen_already = Set.new
Sidekiq::Queue.new(queue_name).each { |job|
key = { job.klass => job.args }
key.in?(seen_already) ? job.delete : seen_already << key
}
end
@KimTrijnh
KimTrijnh / active_record.rb
Created April 21, 2020 09:59 — forked from jackrg/active_record.rb
Add bulk import functionality to Rails Active Record (add this file to config/initializers, call <model>.import!(array-of-record-hashes))
class ActiveRecord::Base
def self.import!(record_list)
raise ArgumentError "record_list not an Array of Hashes" unless record_list.is_a?(Array) && record_list.all? {|rec| rec.is_a? Hash }
return record_list if record_list.empty?
(1..record_list.count).step(1000).each do |start|
key_list, value_list = convert_record_list(record_list[start-1..start+999])
sql = "INSERT INTO #{self.table_name} (#{key_list.join(", ")}) VALUES #{value_list.map {|rec| "(#{rec.join(", ")})" }.join(" ,")}"
self.connection.insert_sql(sql)
@KimTrijnh
KimTrijnh / sidekiq_monitoring
Created April 13, 2020 07:35 — forked from ngsmrk/sidekiq_monitoring
Sidekiq queue checking via rails console
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@KimTrijnh
KimTrijnh / keybase.md
Created September 14, 2019 14:08
Keybase

Keybase proof

I hereby claim:

  • I am kimtrijnh on github.

  • I am kim111 (https://keybase.io/kim111) on keybase.

  • I have a public key ASAeIeMXNnMROye7TEMoeVBxyWSVVLfjPmSpPeRf0p7I2Ao

@KimTrijnh
KimTrijnh / mysql.database.yml
Created July 4, 2019 10:02 — forked from jwo/mysql.database.yml
Sample config/database.yml from Rails. Postgres, MySQL, and SQLite
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
@KimTrijnh
KimTrijnh / iterm2.md
Created July 2, 2019 16:17 — forked from squarism/iterm2.md
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)