Skip to content

Instantly share code, notes, and snippets.

View kidsil's full-sized avatar

Asaf Zamir kidsil

View GitHub Profile
@kidsil
kidsil / hidpi_edp1_hdmi1_layout_solution.sh
Created April 24, 2017 10:36
HiDpi Monitor with external HDMI Monitor xrandr setup
#!/bin/sh
xrandr --output HDMI1 --scale 2x2 --mode 1920x1080 --fb 3840x2160 --pos 3040x0 --rotate normal --primary
xrandr --output eDP1 --scale 1x1 --pos -980x0
@kidsil
kidsil / handler.js
Last active June 17, 2023 16:21
Get AWS Cognito Token ID (JWT) with JavaScript (NodeJS)
const AWS = require('aws-sdk');
const CognitoSDK = require('amazon-cognito-identity-js-node');
AWS.CognitoIdentityServiceProvider.AuthenticationDetails = CognitoSDK.AuthenticationDetails;
AWS.CognitoIdentityServiceProvider.CognitoUserPool = CognitoSDK.CognitoUserPool;
AWS.CognitoIdentityServiceProvider.CognitoUser = CognitoSDK.CognitoUser;
const Username = 'testuser';
const TempPassword = 'TemporaryPassword2!';
const NewPassword = 'NewPassword@#@!19';
const Email = 'some@email.com';
@kidsil
kidsil / jekyll-import-wp.ruby
Created December 1, 2015 11:37
A script to import WordPress posts to Jekyll
require "jekyll-import";
JekyllImport::Importers::WordPress.run({
"dbname" => "db_name",
"user" => "user",
"password" => "",
"host" => "localhost",
"socket" => "",
"table_prefix" => "wp_",
"site_prefix" => "",
"clean_entities" => false,
@kidsil
kidsil / math_with_regex.js
Created March 20, 2015 14:04
Regex Increase number by one (Regex + Math Calculation)
'text_2_moretext'.replace( /(text_)(\d+)(_moretext)/, function( $0, $1, $2, $3 ) {
return $1 + String( parseInt( $2 ) + 1 ) + $3;
});
@kidsil
kidsil / toTitleCase.js
Created October 31, 2014 17:33
To Title Case function on JS
String.prototype.toTitleCase = function() {
return this.replace(/\b\w+/g, function( str ) {
return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
});
jQuery(document).ready(function(){
jQuery( SELECTOR ).text( function( i, text ) { return text.toTitleCase() } );
});
@kidsil
kidsil / convert_grayscale
Created October 29, 2014 20:04
Convert all PNG image files to grayscale (creating a copy named Filename_gray.png)
for f in *.png; do
convert ./"$f" -colorspace Gray ./"${f%.png}_gray.png"
done
@kidsil
kidsil / save_or_load.py
Created May 27, 2013 19:20
load in case of duplicate unique
#Problem is, if I had a unique field, and I'd get an error when trying to save a new object that was conflicting with it,
#I wanted the object to load automatically in case it already exists
#So I wrote a custom save function (which returns the ID in case the object already exists)
def save(self, *args, **kwargs):
try:
super(Place, self).save(*args, **kwargs)
except IntegrityError, e:
existing_object = Place.objects.get(slug=self.slug)
self = existing_object #this doesn't really work for some reason..
super(Place, self).save(*args, **kwargs)
@kidsil
kidsil / slugify.py
Created May 13, 2013 17:06
Special Slugifying German Text in Python (works pretty good actually)
# -*- coding: utf-8 -*-
def replace_all(text, dic):
for replace_with, replace_what in dic.iteritems():
if type(replace_what) is list:
for letter in replace_what:
text = text.replace(letter,replace_with)
else:
text = text.replace(replace_what, replace_with)
return text
@kidsil
kidsil / gist:4973878
Created February 17, 2013 22:44
Yii Model function for getting a name of a table by the relation field
public function get_name_by_relation_field($field) {
$relations = $this->relations();
$obj_name = NULL;
foreach($relations as $relation) {
if (isset($relation[2]) && $relation[2] == $field) {
$obj_name = isset($relation[1])?$relation[1]:NULL;
break;
}
}
return $obj_name;
@kidsil
kidsil / perfectform.html
Created October 13, 2011 09:18
The perfect Form Design
<html>
<head>
<style type="text/css">
label {
display:inline-block;
vertical-align:top; /* if you have a big text area, this would make the label stay at the top */
width:120px;
}
input,textarea {
display:inline-block;