Skip to content

Instantly share code, notes, and snippets.

Avatar

Euccas Chen euccas

View GitHub Profile
@euccas
euccas / Jenkinsfile.groovy
Last active Jun 8, 2020 — forked from Faheetah/Jenkinsfile.groovy
Jenkinsfile idiosynchrasies with escaping and quotes
View Jenkinsfile.groovy
node {
echo 'Results included as an inline comment exactly how they are returned as of Jenkins 2.121, with $BUILD_NUMBER = 1'
echo 'No quotes, pipeline command in single quotes'
sh 'echo $BUILD_NUMBER' // 1
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"' // 1
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"' // 1
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"' // "1"
View react_setState.js
constructor(props) {
super(props)
this.state = {
userName: 'Azat Mardan',
userEmail: 'hi@azat.co',
userId: 3967
}
}
updateValues() {
this.setState({userName: 'Azat'})
View react_fetch_api_data.js
import React, { Component } from "react";
import ReactDOM from "react-dom";
class App extends Component {
constructor() {
super();
this.state = { data: [] };
}
componentDidMount() {
fetch(`https://api.coinmarketcap.com/v1/ticker/?limit=10`)
.then(res => res.json())
@euccas
euccas / yamldiff.py
Last active Jun 8, 2020
compare yaml files, report diff in tags, recursively
View yamldiff.py
def rdiff(yamla, yamlb, path='', key=getkey):
if isinstance(yamla, list) and isinstance(yamlb, list):
for d in listdiff(yamla, yamlb, path=path, key=key):
yield d
elif isinstance(yamla, dict) and isinstance(yamlb, dict):
for d in dictdiff(yamla, yamlb, path=path, key=key):
yield d
else:
if yamla != yamlb:
yield (path, 'value_difference', yamla, '-->', yamlb)
@euccas
euccas / remove_empty_hash_element.rb
Last active Jun 8, 2020
remove empty hash element
View remove_empty_hash_element.rb
def remove_empty_hash_element(h)
if h and h.length>0
h.each do |k,v|
h.delete(k) if v.respond_to?('empty?') and v.empty?
end
end
end
@euccas
euccas / zlib_bi_reverse.cpp
Last active Jun 8, 2020
Zlib function: bits reverse
View zlib_bi_reverse.cpp
/* ===========================================================================
* Reverse the first len bits of a code, using straightforward code (a faster
* method would use a table)
* IN assertion: 1 <= len <= 15
*/
local unsigned bi_reverse(code, len)
unsigned code; /* the value to invert */
int len; /* its bit length */
{
register unsigned res = 0;
@euccas
euccas / read_mem_to_buffer.cpp
Last active Jun 8, 2020
Read memory and store to a 16KB buffer, then output to a file. Pseudo code.
View read_mem_to_buffer.cpp
const size_t buffSize = 16 * 1024; // 16KB
size_t currReadSize = buffSize; // default
size_t dumpedSize = 0;
uint8 currBuff[buffSize];
while (currAddr < endAddr)
{
currReadSize = (currAddr + buffSize <= endAddr) ? buffSize : (size_t)(endAddr - currAddr);
read_memory(currBuff, currAddr, sizeof(uint8) * currReadSize, memory_type);
dumpedSize += currReadSize;
currAddr += currReadSize;
@euccas
euccas / connect_list_items.py
Last active Jun 8, 2020
Generate a string connecting items of a given list. The string should look like: a and b a, b and c Being strict on the separator and "and".
View connect_list_items.py
item_names = mydict["items"].split()
if len(item_names) > 1:
item_names[-1] = "and " + dv_tiers[-1]
sep = ", " if len(item_names) > 2 else " "
namstr = sep.join(item_names)
print namestr # a, b and c
View jenkins_copy_jobs_in_view.groovy
import hudson.model.*
def str_view = "AIR_Project_A630"
def str_search = "air_a630"
def str_replace = "air_a630v1"
def view = Hudson.instance.getView(str_view)
//copy all projects of a view
for(item in view.getItems())
@euccas
euccas / test_jsonb.rb
Last active Jun 8, 2020
postgresql JSONB
View test_jsonb.rb
require 'pg'
require 'json'
def db_connect(host, dbname, user, password)
begin
conn = PGconn.connect(host, 5436, '', '', dbname, user, password)
rescue
puts "Failed to connect to database #{dbname} on #{host}"
end
return conn
You can’t perform that action at this time.